generate

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package generate implements `gombit generate`: it regenerates a gombit application's model-first resource files (the generator-owned *.gen.go DTOs and handler) from the app's real compiled GORM models, and, with Check, verifies they are up to date without mutating anything.

Model-first generation must read the ACTUAL current model — the one the developer may have edited — so it cannot work off the make-resource CLI grammar or off source it just wrote. Like migrations (ADR-012), it uses Program Mode: a throwaway `main` is written into the app module and `go run`, importing the app's model packages and calling resourcegen.RenderResource on each. That loader is a pure function — it emits the artifacts (path, bytes, ownership) as JSON and has no write access to the app tree. This package (the parent) owns all filesystem policy: which files are overwritten, which are seeded once, and what --check compares.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Generate

func Generate(ctx context.Context, opts Options) error

Generate regenerates (or, with Check, verifies) the model-first resource files.

func PlanResource

func PlanResource(ctx context.Context, opts Options, pend resourcegen.Pending) ([]resourcegen.GeneratedArtifact, error)

PlanResource runs the Program-Mode phase-2 render for a single pending (not-yet-written) resource and returns its generator-owned + seed artifacts WITHOUT writing anything. The pending model is compiled through a Go build overlay (pend.Overlay) that isolates it from the stale generated files this run replaces, so the loader can reflect the new model while the real app tree stays untouched and local replace directives keep their meaning — go run executes from the real module root. This renders the artifacts; ValidateResource then compiles the whole committed package (including preserved human-owned files) against them.

func ValidateResource

func ValidateResource(ctx context.Context, opts Options, pend resourcegen.Pending, overlay map[string][]byte) error

ValidateResource compiles the resource package exactly as make resource will commit it — the new model, the freshly rendered *.gen.go, and every preserved human-owned file (hooks and any hand-written code, read from disk) — via an overlay of the final tree, WITHOUT writing anything. It is the second half of the phase-2 preflight: PlanResource renders against an isolated model, but the customization the commit keeps (a hooks.go that reads a model field, say) is only exercised here, so a resource whose preserved code no longer matches the regenerated model fails closed before any file changes. overlay stages just the files this run will write; kept and hand-written files come from disk.

Types

type Options

type Options struct {
	WorkDir string
	// Check renders in temp space and compares against the committed
	// generator-owned files instead of writing; it fails on any difference and
	// never mutates the tree (a CI drift gate). Seed-once files are ignored.
	Check bool
	// DryRun prints what a write run would do without writing.
	DryRun bool
	Stdout io.Writer
	Stderr io.Writer
	// contains filtered or unexported fields
}

Options configures a generate run.

Jump to

Keyboard shortcuts

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