codegen

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2021 License: Apache-2.0 Imports: 35 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
var (
	ErrNotAFile           = errors.New("not a file")
	ErrNoHeadBranch       = errors.New("failed to find a head branch, does one exist?")
	ErrNoRemoteHeadBranch = errors.New("failed to get head branch from remote origin")
)

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

func (b *Builder) FetchTemplate(ctx context.Context, filePath string) (io.Reader, error)

FetchTemplate fetches a template from a git repository

func (*Builder) FormatFiles

func (b *Builder) FormatFiles(ctx context.Context) error

func (*Builder) GenerateFiles

func (b *Builder) GenerateFiles(ctx context.Context, fs billy.Filesystem) ([]string, error)

GenerateFiles walks the vfs generated by Run() and renders the templates

func (*Builder) HasDeviations

func (b *Builder) HasDeviations(_ context.Context, filePath string) bool

HasDeviations looks for deviation blocks in a file, returning true if they exist

func (*Builder) PostCodegenProcessors added in v1.1.0

func (b *Builder) PostCodegenProcessors(ctx context.Context, log logrus.FieldLogger) error

PostCodegenProcessors runs any post-codgegen processors and reruns codegen if any of them require that.

func (*Builder) PreCodegenProcessors added in v1.1.0

func (b *Builder) PreCodegenProcessors(ctx context.Context, log logrus.FieldLogger) error

PreCodegenProcessors runs any pre-codgegen processors.

func (*Builder) ProcessWalkFunc added in v1.1.0

func (b *Builder) ProcessWalkFunc(preCodegen bool, log logrus.FieldLogger) filepath.WalkFunc

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

func (b *Builder) Run(ctx context.Context) ([]string, error)

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) 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.

Jump to

Keyboard shortcuts

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