gen

package
v0.6.9-alpha.9 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const CUE_VENDOR_DIR = "cue.mod/pkg"

Variables

This section is empty.

Functions

func FormatCue added in v0.6.9

func FormatCue(val cue.Value, opts []cue.Option, pkg string) ([]byte, error)

func FormatJson added in v0.6.9

func FormatJson(val cue.Value, escape bool) ([]byte, error)

func FormatToml added in v0.6.9

func FormatToml(val cue.Value) ([]byte, error)

func FormatXml added in v0.6.9

func FormatXml(val cue.Value) ([]byte, error)

func FormatYaml added in v0.6.9

func FormatYaml(val cue.Value) ([]byte, error)

Types

type File

type File struct {
	// Input Data, local to this file
	// this can sometimes be a list for Adhoc
	In any

	// The full path under the output location
	// empty implies don't generate, even though it may endup in the list
	Filepath string

	// Template parameters (only one should be set at a time i.e. != "")
	TemplateContent string // The content, takes precedence over next option
	TemplatePath    string // Named template
	DatafileFormat  string // Data format file
	StaticFile      bool

	// Formatting
	FormattingDisabled bool
	FormattingConfig   *FmtConfig

	// Template delimiters
	TemplateDelims templates.Delims

	// CUE settings
	Package        string
	Raw            bool
	Final          bool
	Concrete       bool
	Definitions    bool
	Optional       bool
	Hidden         bool
	Attributes     bool
	Docs           bool
	InlineImports  bool
	ErrorsAsValues bool

	// CUE value for datafiles
	// (we use a different name here so that it does not automatically try to decode, which would require concreteness)
	Value cue.Value

	// Template Instance Pointer
	//   If local, this will be created when the template content is loaded
	//   If a named template, actual template lives in the generator and is created at folder import time
	TemplateInstance *templates.Template

	// Content
	RenderContent []byte
	FinalContent  []byte

	// Shadow related
	ShadowFile *File
	UserFile   *File

	DoWrite bool

	// Bookkeeping
	Errors []error
	FileStats
	// contains filtered or unexported fields
}

func (*File) FormatData added in v0.6.9

func (F *File) FormatData(val cue.Value, format string) ([]byte, error)

func (*File) FormatRendered

func (F *File) FormatRendered() (err error)

func (*File) MergeIn added in v0.6.8

func (F *File) MergeIn(other map[string]any)

func (*File) ReadUser

func (F *File) ReadUser(outdir string) error

read the file contents relative to the output dir

func (*File) Render

func (F *File) Render(outdir string, UseDiff3, NoFmt bool) error

func (*File) RenderData added in v0.6.1

func (F *File) RenderData() (err error)

func (*File) RenderTemplate

func (F *File) RenderTemplate(nofmt bool) (err error)

func (*File) UnifyContent

func (F *File) UnifyContent(UseDiff3 bool) (write bool, err error)

func (*File) WriteOutput

func (F *File) WriteOutput(basedir string) error

func (*File) WriteShadow

func (F *File) WriteShadow(basedir string) error

type FileStats

type FileStats struct {
	// using 0 (false) and 1 (true) for easier summation code below
	IsNew     int
	IsSame    int
	IsSkipped int
	IsWritten int
	IsErr     int

	IsModified       int
	IsModifiedRender int
	IsModifiedOutput int
	IsModifiedDiff3  int
	IsConflicted     int

	RenderingTime time.Duration
	CompareTime   time.Duration
	TotalTime     time.Duration
}

type FmtConfig added in v0.6.5

type FmtConfig struct {
	Formatter string
	Config    interface{}
}

type Generator

type Generator struct {
	*hof.Node[Generator]
	//
	// Set by Hof via cuelang extraction
	// Label in Cuelang
	Name string

	// Base directory for output
	Outdir string

	// Other important dirs when loading templates (auto set)
	CueModuleRoot  string
	RootModuleName string
	WorkingDir     string
	CwdToRoot      string // module root <- working dir (../..)

	// "Global" input, merged with out replacing onto the files
	In  map[string]any
	Val cue.Value

	// File globs to watch and trigger regen on change
	WatchFull []string
	WatchFast []string

	// Formatting
	FormattingDisabled bool
	FormatData         bool
	FormattingConfigs  map[string]FmtConfig

	// The list fo files for hof to generate, in cue values
	Out []*File

	Templates []*TemplateGlobs
	Partials  []*TemplateGlobs

	// Filepath globs for static files to load
	Statics []*StaticGlobs

	// The following will be automatically added to the template context
	// under its name for reference in GenFiles  and partials in templates
	EmbeddedTemplates map[string]*TemplateContent
	EmbeddedPartials  map[string]*TemplateContent

	// Static files are available for pure cue generators that want to have static files
	// These should be named by their filepath, but be the content of the file
	EmbeddedStatics map[string]string

	// Subgenerators for composition
	Generators map[string]*Generator

	// Used for indexing into the vendor directory...
	// This should be `ModuleName: string | *"github.com/..." in your generator
	// and set to "" if you use the generator from within the module itself
	ModuleName string

	// Use Diff3 & Shadow
	Diff3FlagSet bool // set by flag
	UseDiff3     bool
	NoFormat     bool

	// enable pre/post-flows
	ExecFlows bool

	// Disabled? we do this when looking at expressions and optimizing
	// TODO, make this field available in cuelang?
	Disabled bool

	// Template System Cache
	TemplateMap templates.TemplateMap
	PartialsMap templates.TemplateMap

	// Files and the shadow dir for doing neat things
	OrderedFiles []*File
	Files        map[string]*File
	Shadow       map[string]*File

	// Print extra information
	Debug     bool
	Verbosity int

	// Status for this generator and processing
	Stats *GeneratorStats

	// Cuelang related, also set externally
	CueValue cue.Value
	// contains filtered or unexported fields
}

A generator pulled from the cue instances

func NewGenerator

func NewGenerator(node *hof.Node[Generator]) *Generator

func (*Generator) CleanupRemainingShadow added in v0.6.5

func (G *Generator) CleanupRemainingShadow(outputDir, shadowDir string, verbosity int, keepDeleted bool) (errs []error)

func (*Generator) CleanupShadow added in v0.6.8

func (G *Generator) CleanupShadow(outputBase, shadowBase string, verbosity int, keepDeleted bool) (errs []error)

func (*Generator) DecodeFromCUE added in v0.6.5

func (G *Generator) DecodeFromCUE(root cue.Value) (errs []error)

func (*Generator) GenerateFiles

func (G *Generator) GenerateFiles(outdir string) []error

func (*Generator) Initialize added in v0.2.9

func (G *Generator) Initialize() []error

func (*Generator) LoadShadow added in v0.6.7

func (G *Generator) LoadShadow(basedir string) error

func (*Generator) NamePath added in v0.6.5

func (G *Generator) NamePath() string

Returns Generators name path, including parents as a path like string

func (*Generator) OutputPath added in v0.6.5

func (G *Generator) OutputPath() string

Returns Generators contribution to the output path, including parents contributions if a subgen. Each gen in the path is [parent]/G.Outdir

func (*Generator) PrintInfo added in v0.6.7

func (G *Generator) PrintInfo()

func (*Generator) ResolveFile added in v0.2.9

func (G *Generator) ResolveFile(F *File) error

func (*Generator) RunPostFlow added in v0.6.9

func (G *Generator) RunPostFlow() error

func (*Generator) RunPreFlow added in v0.6.9

func (G *Generator) RunPreFlow() error

func (*Generator) ShadowPath added in v0.6.5

func (G *Generator) ShadowPath() string

Returns Generators contribution to the shadow path, including parents contributions if a subgen. Each gen in the path is [parent]/G.Name/G.Outdir

func (*Generator) Write added in v0.6.8

func (G *Generator) Write(outputBase, shadowBase string) (errs []error)

type GeneratorStats

type GeneratorStats struct {
	NumNew     int
	NumSame    int
	NumSkipped int
	NumDeleted int
	NumWritten int
	NumStatic  int
	NumErr     int
	TotalFiles int

	NumModified       int
	NumModifiedRender int
	NumModifiedOutput int
	NumModifiedDiff3  int
	NumConflicted     int

	LoadingTime   time.Duration
	RenderingTime time.Duration
	WritingTime   time.Duration
	TotalTime     time.Duration
}

func (*GeneratorStats) CalcTotals

func (S *GeneratorStats) CalcTotals(G *Generator) error

func (*GeneratorStats) String

func (S *GeneratorStats) String() string

type StaticGlobs added in v0.6.0

type StaticGlobs struct {
	// Globs to load
	Globs []string
	// Prefix to trim
	TrimPrefix string
	// Prefix to add before output
	OutPrefix string
}

type TemplateContent added in v0.6.0

type TemplateContent struct {
	Content string
	Delims  templates.Delims
}

type TemplateGlobs added in v0.6.0

type TemplateGlobs struct {
	// Globs to load
	Globs []string
	// Prefix to trim
	TrimPrefix string
	// Custom delims
	Delims     templates.Delims
	DelimGlobs map[string]templates.Delims
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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