Documentation
¶
Overview ¶
Package codegen has code generators for Go projects
This is intended for use with stencil but can also be used outside of it.
Using configuration.ServiceManifest, a list of template repositories is created and cloned into a layered filesystem with the sub-dependencies of the root dependency (the module) being used first, and so on. This layered fs is then walked to find all files with a `.tpl` extension. These are rendred and turned into functions.RenderedTemplate objects, and then written to disk based on the template's function calls.
This is the core of stencil
Index ¶
- Variables
- type Builder
- func (b *Builder) FetchTemplate(ctx context.Context, filePath string) (io.Reader, error)
- func (b *Builder) FormatFiles(ctx context.Context) error
- func (b *Builder) GenerateFiles(ctx context.Context, fs billy.Filesystem) ([]string, error)
- func (b *Builder) HasDeviations(_ context.Context, filePath string) bool
- func (b *Builder) PostCodegenProcessors(ctx context.Context, log logrus.FieldLogger) error
- func (b *Builder) PreCodegenProcessors(ctx context.Context, log logrus.FieldLogger) error
- func (b *Builder) ProcessWalkFunc(preCodegen bool, log logrus.FieldLogger) filepath.WalkFunc
- func (b *Builder) Run(ctx context.Context) ([]string, error)
- func (b *Builder) WriteTemplate(ctx context.Context, filePath, contents string, args map[string]interface{}) ([]string, error)
- type Fetcher
- func (f *Fetcher) CreateVFS(ctx context.Context) (billy.Filesystem, []*configuration.TemplateRepositoryManifest, error)
- func (f *Fetcher) DownloadRepository(ctx context.Context, r *configuration.TemplateRepository) (billy.Filesystem, error)
- func (f *Fetcher) ParseRepositoryManifest(fs billy.Filesystem) (*configuration.TemplateRepositoryManifest, error)
- func (f *Fetcher) ResolveDependencies(ctx context.Context, filesystems map[string]bool, ...) ([]billy.Filesystem, error)
Constants ¶
This section is empty.
Variables ¶
Functions ¶
This section is empty.
Types ¶
type Builder ¶
type Builder struct {
Branch string
Repo string
Dir string
Manifest *configuration.ServiceManifest
GitRepoFs billy.Filesystem
Processors *processors.Runner
// contains filtered or unexported fields
}
func NewBuilder ¶
func NewBuilder(repo, dir string, log logrus.FieldLogger, s *configuration.ServiceManifest, sshKeyPath string, accessToken cfg.SecretData) *Builder
NewBuilder returns a new builder
func (*Builder) FetchTemplate ¶
FetchTemplate fetches a template from a git repository
func (*Builder) GenerateFiles ¶
GenerateFiles walks the vfs generated by Run() and renders the templates
func (*Builder) HasDeviations ¶
HasDeviations looks for deviation blocks in a file, returning true if they exist
func (*Builder) PostCodegenProcessors ¶ added in v1.1.0
PostCodegenProcessors runs any post-codgegen processors and reruns codegen if any of them require that.
func (*Builder) PreCodegenProcessors ¶ added in v1.1.0
PreCodegenProcessors runs any pre-codgegen processors.
func (*Builder) ProcessWalkFunc ¶ added in v1.1.0
ProcessWalkFunc implements a filepath.WalkFunc function that runs either post or pre processors (depending on params passed in) on all files. If preCodegen is false, it is assumed to be post-codegen.
func (*Builder) Run ¶
Run fetches dependencies of the root modules and builds the layered filesystem, after that GenerateFiles is called to actually walk the filesystem and render the templates. This step also does minimal post-processing of the dependencies manifes.yamls.
func (*Builder) WriteTemplate ¶
func (b *Builder) WriteTemplate(ctx context.Context, filePath, contents string, args map[string]interface{}) ([]string, error)
WriteTemplate handles parsing commands (e.g. ///Block) and renders a given template by turning it into a functions.RenderedTemplate. This is then written to disk, or skipped based on the template's function call. Multiple functions.RenderedTemplates can be returned by a single template.
type Fetcher ¶
type Fetcher struct {
// contains filtered or unexported fields
}
func NewFetcher ¶
func NewFetcher(log logrus.FieldLogger, m *configuration.ServiceManifest, sshKeyPath string, accessToken cfg.SecretData, extHost *extensions.Host) *Fetcher
func (*Fetcher) CreateVFS ¶
func (f *Fetcher) CreateVFS(ctx context.Context) (billy.Filesystem, []*configuration.TemplateRepositoryManifest, error)
func (*Fetcher) DownloadRepository ¶
func (f *Fetcher) DownloadRepository(ctx context.Context, r *configuration.TemplateRepository) (billy.Filesystem, error)
func (*Fetcher) ParseRepositoryManifest ¶
func (f *Fetcher) ParseRepositoryManifest(fs billy.Filesystem) (*configuration.TemplateRepositoryManifest, error)
func (*Fetcher) ResolveDependencies ¶
func (f *Fetcher) ResolveDependencies(ctx context.Context, filesystems map[string]bool, r *configuration.TemplateRepositoryManifest) ([]billy.Filesystem, error)
ResolveDependencies resolved the dependencies of a given template repository. It currently only supports one level dependency resolution and doesn't do any smart logic for ordering other than first wins.