scaffold

package
v0.4.2-alpha.1 Latest Latest
Warning

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

Go to latest
Published: May 26, 2022 License: Apache-2.0 Imports: 23 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 (
	// 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 CopyTemplateFiles

func CopyTemplateFiles(
	sourceDir, destDir string, force bool,
	projectName string, projectConfigs map[string]interface{},
	stack2Configs map[string]map[string]interface{},
) error

CopyTemplateFiles does the actual copy operation to a destination directory.

func GenInternalTemplates

func GenInternalTemplates() error

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

func GetTemplateDir

func GetTemplateDir(subDir string) (string, error)

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

func IsTemplateURL

func IsTemplateURL(templateNamePathOrURL string) bool

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

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.

Types

type FieldTemplate

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

func (*FieldTemplate) RestoreActualValue

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

type FieldType

type FieldType string
const (
	StringField FieldType = "string"
	IntField    FieldType = "int"
	BoolField   FieldType = "bool"
	FloatField  FieldType = "float"
	ArrayField  FieldType = "array"
	StructField FieldType = "struct"
)

func (FieldType) IsPrimitive

func (f FieldType) IsPrimitive() bool

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"`
	// CommonTemplates contains configuration in project level
	CommonTemplates []*FieldTemplate `json:"common,omitempty" yaml:"common,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 fields wait to be prompt
	Fields []*FieldTemplate `json:"fields,omitempty" yaml:"fields,omitempty"`
}

type Template

type Template struct {
	Dir  string // The directory containing kusion.yaml.
	Name string // The name of the template.

	// following fields come from ProjectTemplate
	ProjectName   string           // The name of the project.
	Description   string           // Description of the template.
	Quickstart    string           // Optional text to be displayed after template creation.
	CommonConfigs []*FieldTemplate // CommonConfigs contains configuration in stack level
	StackConfigs  []*StackTemplate // StackConfigs contains configuration in stack level
}

Template represents a project template.

func LoadTemplate

func LoadTemplate(path string) (Template, error)

LoadTemplate returns a template from a path.

type TemplateRepository

type TemplateRepository struct {
	Root         string // The full path to the root directory of the repository.
	SubDirectory string // The full path to the sub directory 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)

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