codegen

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2022 License: Apache-2.0 Imports: 34 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 {
	// contains filtered or unexported fields
}

Builder is the heart of stencil, running it is akin to running stencil. Builder handles fetching stencil dependencies and running the actual templating engine and writing the results to disk. Also handled is the extension framework

func NewBuilder

func NewBuilder(repo, dir string, log logrus.FieldLogger, s *configuration.ServiceManifest,
	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) 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
}

Fetcher handles all interactions between dependencies and fetching of dependencies for stencil. This involes creating a vfs, parsing repository manifests, etc.

func NewFetcher

func NewFetcher(log logrus.FieldLogger, m *configuration.ServiceManifest, accessToken cfg.SecretData,
	extHost *extensions.Host) *Fetcher

NewFetcher creates a new fetcher instance

func (*Fetcher) CreateVFS

CreateVFS creates a new virtual file system with the dependencies of the top level (service) module inside of it. This filesystem is ordered as such that the top level modules always go first, with the order in that list being preserved. After a VFS is created, all the manifests from said repositories are then parsed and returned to the caller in the order that they were layered.

func (*Fetcher) DownloadRepository

func (f *Fetcher) DownloadRepository(ctx context.Context, r *configuration.TemplateRepository) (billy.Filesystem, error)

DownloadRepository downloads a remote repository into memory based on the URL provided. If this is a file:// repository fs.New is used instead to "chroot" it.

func (*Fetcher) ParseRepositoryManifest

func (f *Fetcher) ParseRepositoryManifest(fs billy.Filesystem) (*configuration.TemplateRepositoryManifest, error)

ParseRepositoryManifest parses a remote repository manifest

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