scaffold

package
v0.9.1-beta Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 9, 2023 License: Apache-2.0 Imports: 21 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// BaseTemplateDir is the name of the directory containing templates.
	BaseTemplateDir = "templates"
	// InternalTemplateDir is the name of the directory containing internal templates.
	InternalTemplateDir = "templates/internal"
	// ExternalTemplateDir is the name of the directory containing external templates.
	ExternalTemplateDir = "templates/external"
	// GitDir is the name of the folder git uses to store information.
	GitDir = ".git"
	// KusionYaml is a config file which describe all params of a template
	KusionYaml = "kusion.yaml"
)

Variables

View Source
var (
	// file flag, create or upate
	CreateOrUpdate = os.O_WRONLY | os.O_CREATE | os.O_TRUNC
	// default directory permission, 700
	DefaultDirectoryPermission os.FileMode = 0o700
	// default file permission, 600
	DefaultFilePermission os.FileMode = 0o600
)
View Source
var (
	// KusionTemplateGitRepository is the Git URL for Kusion program templates
	KusionTemplateGitRepository = "https://github.com/KusionStack/kusion-templates"
)

These are variables instead of constants in order that they can be set using the `-X` `ldflag` at build time, if necessary.

Functions

func GenInternalTemplates

func GenInternalTemplates() error

GenInternalTemplates save localTemplates(FS) to internal-templates(target directory)

func GetInternalTemplates added in v0.5.0

func GetInternalTemplates() embed.FS

Export internal templates which is embed in binary

func GetTemplateDir

func GetTemplateDir(subDir string) (string, error)

GetTemplateDir returns the directory in which templates on the current machine are stored.

func InternalTemplateNameToPath added in v0.5.0

func InternalTemplateNameToPath() map[string]string

InternalTemplateNameToPath return a map of template name to path

func IsTemplateURL

func IsTemplateURL(templateNamePathOrURL string) bool

IsTemplateURL returns true if templateNamePathOrURL starts with "https://".

func ReadTemplate added in v0.5.0

func ReadTemplate(dir string, fs afero.Fs) error

Read files' content from local dir into file system

func RenderFSTemplate added in v0.5.0

func RenderFSTemplate(srcFS afero.Fs, srcDir string, destFS afero.Fs, destDir string, tc *TemplateConfig) error

RenderFSTemplate does the actual copy operation from source FS to destination FS.

func RenderLocalTemplate added in v0.5.0

func RenderLocalTemplate(sourceDir, destDir string, force bool, tc *TemplateConfig) error

RenderLocalTemplate does the actual copy operation from source directory to a destination directory.

func Transfer added in v0.5.0

func Transfer(srcFS embed.FS) (afero.Fs, error)

Transfer embed.FS into afero.Fs

func ValidateProjectName

func ValidateProjectName(s string) error

ValidateProjectName ensures a project name is valid, if it is not it returns an error with a message suitable for display to an end user.

func WriteToDisk added in v0.5.0

func WriteToDisk(destFS afero.Fs, root string, force bool) error

Walk destination file system and persist each file to local disk

Types

type FieldTemplate

type FieldTemplate struct {
	// Name represents the field name, required
	Name string `json:"name,omitempty" yaml:"name,omitempty"`
	// Description represents the field description, optional
	Description string `json:"description,omitempty" yaml:"description,omitempty"`
	// Type can be string/int/bool/float/array/map/struct/any, required
	Type FieldType `json:"type,omitempty" yaml:"type,omitempty"`
	// Default represents default value for all FieldType
	Default interface{} `json:"default,omitempty" yaml:"default,omitempty"`
	// Elem is effective only when type is ArrayField
	Elem *FieldTemplate `json:"elem,omitempty" yaml:"elem,omitempty"`
	// Key is effective only when type is MapField
	Key *FieldTemplate `json:"key,omitempty" yaml:"key,omitempty"`
	// Value is effective only when type is MapField
	Value *FieldTemplate `json:"value,omitempty" yaml:"value,omitempty"`
	// Fields is effective only when type is StructField
	Fields []*FieldTemplate `json:"fields,omitempty" yaml:"fields,omitempty"`
}

FieldTemplate can describe all kinds of type, including primitive and composite.

func (*FieldTemplate) RestoreActualValue

func (f *FieldTemplate) RestoreActualValue(input string) (actual interface{}, err error)

RestoreActualValue help to transfer input to actual value according to its type

type FieldType

type FieldType string

FieldType includes field type that can be unmarshalled directly

const (
	StringField FieldType = "string"
	IntField    FieldType = "int"
	BoolField   FieldType = "bool"
	FloatField  FieldType = "float"
	ArrayField  FieldType = "array"
	MapField    FieldType = "map"
	StructField FieldType = "struct"
	AnyField    FieldType = "any" // AnyField equal to interface{}
)

func (FieldType) IsPrimitive

func (f FieldType) IsPrimitive() bool

IsPrimitive indicate the give field is one of StringField, IntField, FloatField, BoolField or not

type ProjectTemplate

type ProjectTemplate struct {
	// ProjectName is a required fully qualified name.
	ProjectName string `json:"projectName" yaml:"projectName"`
	// Description is an optional description of the template.
	Description string `json:"description,omitempty" yaml:"description,omitempty"`
	// Quickstart contains optional text to be displayed after template creation.
	Quickstart string `json:"quickstart,omitempty" yaml:"quickstart,omitempty"`
	// ProjectFields contains configuration in project level
	ProjectFields []*FieldTemplate `json:"projectFields,omitempty" yaml:"projectFields,omitempty"`
	// StackTemplates contains configuration in stack level
	StackTemplates []*StackTemplate `json:"stacks,omitempty" yaml:"stacks,omitempty"`
}

ProjectTemplate is a Kusion project template manifest.

func LoadProjectTemplate

func LoadProjectTemplate(path string) (*ProjectTemplate, error)

LoadProjectTemplate reads a project definition from a file.

type StackTemplate

type StackTemplate struct {
	// Name is stack name
	Name string `json:"name" yaml:"name"`
	// Fields contains all stack fields definition
	Fields []*FieldTemplate `json:"fields,omitempty" yaml:"fields,omitempty"`
}

StackTemplates contains configuration in stack level

type Template

type Template struct {
	// The directory containing kusion.yaml.
	Dir string `json:"dir,omitempty" yaml:"dir,omitempty"`
	// The name of the template.
	Name string `json:"name,omitempty" yaml:"name,omitempty"`

	*ProjectTemplate
}

Template represents a project template.

func LoadTemplate

func LoadTemplate(path string) (Template, error)

LoadTemplate returns a template from a path.

type TemplateConfig added in v0.4.4

type TemplateConfig struct {
	// ProjectName is project name, as well as root dir name
	ProjectName string `json:"projectName"`
	// ProjectConfig contains configuration in project level
	ProjectConfig map[string]interface{} `json:"projectConfig,omitempty"`
	// StacksConfig contains configuration in stack level, can be multi-stack or single-stack
	StacksConfig map[string]map[string]interface{} `json:"stacksConfig,omitempty"`
}

TemplateConfig contains all config items to render the chosen project

type TemplateRepository

type TemplateRepository struct {
	Root         string // The full path to the root directory of the repository.
	SubDirectory string // The full path to the subdirectory within the repository.
	ShouldDelete bool   // Whether the root directory should be deleted.
}

TemplateRepository represents a repository of templates.

func RetrieveTemplates

func RetrieveTemplates(templateNamePathOrURL string, online bool) (TemplateRepository, error)

RetrieveTemplates retrieves a "template repository" based on the specified name, path, or URL.

func (TemplateRepository) Delete

func (repo TemplateRepository) Delete() error

Delete deletes the template repository.

func (TemplateRepository) Templates

func (repo TemplateRepository) Templates() ([]Template, error)

Templates lists the templates in the repository.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL