codegen

package
v0.0.0-...-988ea4c Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2023 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ComposableLatestMajorsOrXJenny

func ComposableLatestMajorsOrXJenny(parentdir string, inner codejen.OneToOne[SchemaForGen]) codejen.OneToMany[kindsys.Composable]

TODO remove this once there's a standard jenny for this...somewhere in core

func PostprocessGoFile

func PostprocessGoFile(cfg GenGoFile) ([]byte, error)

func PrefixDropper

func PrefixDropper(prefix string) dstutil.ApplyFunc

PrefixDropper returns a dstutil.ApplyFunc that removes the provided prefix string when it appears as a leading sequence in type names, var names, and comments in a generated Go file.

func PrefixReplacer

func PrefixReplacer(prefix, replace string) dstutil.ApplyFunc

PrefixReplacer returns a dstutil.ApplyFunc that removes the provided prefix string when it appears as a leading sequence in type names, var names, and comments in a generated Go file.

When an exact match for prefix is found, the provided replace string is substituted.

func Prefixer

func Prefixer(prefix string) codejen.FileMapper

Prefixer returns a FileMapper that injects the provided path prefix to files passed through it.

func SlashHeaderMapper

func SlashHeaderMapper(maingen string) codejen.FileMapper

SlashHeaderMapper produces a FileMapper that injects a comment header onto a codejen.File indicating the main generator that produced it (via the provided maingen, which should be a path) and the jenny or jennies that constructed the file.

Types

type GenGoFile

type GenGoFile struct {
	Path                    string
	Appliers                []dstutil.ApplyFunc
	In                      []byte
	IgnoreDiscoveredImports bool
}

type GenTest

type GenTest struct {
	// contains filtered or unexported fields
}

func NewGenTest

func NewGenTest(t *testing.T, config GenTestConfig) GenTest

func (GenTest) ModuleToCoreKind

func (genTest GenTest) ModuleToCoreKind(modulePath string) (kindsys.Core, error)

func (GenTest) Run

func (genTest GenTest) Run(inner func(t *testing.T) codejen.Files)

func (GenTest) RunManyToOneFromModule

func (genTest GenTest) RunManyToOneFromModule(modulePath string, jenny ManyToOne)

func (GenTest) RunOneToManyFromModule

func (genTest GenTest) RunOneToManyFromModule(modulePath string, jenny OneToMany)

func (GenTest) RunOneToOneFromModule

func (genTest GenTest) RunOneToOneFromModule(modulePath string, jenny OneToOne)

type GenTestConfig

type GenTestConfig struct {
	OutputDir string
}

type GoTypesJenny

type GoTypesJenny struct {
	ApplyFuncs       []dstutil.ApplyFunc
	ExpandReferences bool
}

GoTypesJenny is a OneToOne that produces Go types for the provided thema.Schema.

func (GoTypesJenny) Generate

func (j GoTypesJenny) Generate(sfg SchemaForGen) (*codejen.File, error)

func (GoTypesJenny) JennyName

func (j GoTypesJenny) JennyName() string

type JsonSchemaJenny

type JsonSchemaJenny struct{}

func (JsonSchemaJenny) Generate

func (j JsonSchemaJenny) Generate(sfg SchemaForGen) (*codejen.File, error)

func (JsonSchemaJenny) JennyName

func (j JsonSchemaJenny) JennyName() string

type ManyToMany

type ManyToMany codejen.ManyToMany[kindsys.Kind]

type ManyToOne

type ManyToOne codejen.ManyToOne[kindsys.Kind]

type OneToMany

type OneToMany codejen.OneToMany[kindsys.Kind]

func LatestMajorsOrXJenny

func LatestMajorsOrXJenny(parentdir string, forceGroup bool, inner codejen.OneToOne[SchemaForGen]) OneToMany

LatestMajorsOrXJenny returns a jenny that repeats the input for the latest in each major version.

TODO remove forceGroup option, it's a temporary hack to accommodate core kinds

type OneToOne

type OneToOne codejen.OneToOne[kindsys.Kind]

func LatestJenny

func LatestJenny(parentdir string, inner codejen.OneToOne[SchemaForGen]) OneToOne

LatestJenny returns a jenny that runs another jenny for only the latest schema in a DefForGen, and prefixes the resulting file with the provided parentdir (e.g. "pkg/kinds/") and with a directory based on the kind's machine name (e.g. "dashboard/").

type SchemaForGen

type SchemaForGen struct {
	// The PascalCase name of the schematized type.
	Name string
	// The schema to be rendered for the type itself.
	Schema thema.Schema
	// Whether the schema is grouped. See https://github.com/grafana/thema/issues/62
	IsGroup bool
}

SchemaForGen is an intermediate values type for jennies that holds both a thema.Schema, and values relevant to generating the schema that should properly, eventually, be in thema itself.

TODO this will be replaced by thema-native constructs

func ForLatestSchema

func ForLatestSchema(k kindsys.Kind) SchemaForGen

ForLatestSchema returns a SchemaForGen for the latest schema in the provided kindsys.Kind's lineage.

TODO this will be replaced by thema-native constructs

type TSResourceJenny

type TSResourceJenny struct {
	ImportMapper cuetsy.ImportMapper
}

TSResourceJenny is a OneToOne that produces TypeScript types and defaults for a Thema schema.

Thema's generic TS jenny will be able to replace this one once https://github.com/grafana/thema/issues/89 is complete.

func (TSResourceJenny) Generate

func (j TSResourceJenny) Generate(sfg SchemaForGen) (*codejen.File, error)

func (TSResourceJenny) JennyName

func (j TSResourceJenny) JennyName() string

type TSTypesJenny

type TSTypesJenny struct {
	ImportMapper cuetsy.ImportMapper
}

TSTypesJenny is a OneToOne that produces TypeScript types and defaults for a Thema schema.

Thema's generic TS jenny will be able to replace this one once https://github.com/grafana/thema/issues/89 is complete.

func (TSTypesJenny) Generate

func (j TSTypesJenny) Generate(sfg SchemaForGen) (*codejen.File, error)

func (TSTypesJenny) JennyName

func (j TSTypesJenny) JennyName() string

Jump to

Keyboard shortcuts

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