generate

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package generate scaffolds Puzzle source files — components, views, layouts, and models — from frozen-grammar stub templates (constellation/doc/DOC-SPEC.md §6, §7, §11). It never parses or rewrites JavaScript (decision D3): the model registry (app/models/index.js) is left untouched and the caller prints a hint instead. All generated .pzl output is exercised by the repo's own parser+codegen in generate_test.go, so a scaffold is guaranteed to compile.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindProjectRoot

func FindProjectRoot(start string) (string, error)

FindProjectRoot walks up from start (inclusive) until it finds a directory holding package.json or puzzle.config.js, stopping at the filesystem root.

Types

type Kind

type Kind string

Kind selects which scaffold to emit.

const (
	KindComponent Kind = "component"
	KindView      Kind = "view"
	KindLayout    Kind = "layout"
	KindModel     Kind = "model"
)

func ParseKind

func ParseKind(s string) (Kind, error)

ParseKind maps a CLI type argument to a Kind, or errors with the valid set.

type Options

type Options struct {
	// Root is the project root (holds package.json / puzzle.config.js).
	Root string
	// Kind is the file type to generate.
	Kind Kind
	// Name is the component/view/layout PascalCase name, or the lower-case
	// singular model name.
	Name string
	// Dir overrides the output directory, relative to Root. Empty uses the
	// per-kind default.
	Dir string
	// Force allows overwriting an existing file.
	Force bool
}

Options describe one scaffold request.

type Result

type Result struct {
	// Path is the absolute path of the written file.
	Path string
	// Rel is Path relative to the project root (for display).
	Rel string
	// Hint is a non-empty, multi-line instruction when the user must take a
	// manual follow-up step (model registration); empty otherwise.
	Hint string
}

Result reports what Generate produced.

func Generate

func Generate(opts Options) (*Result, error)

Generate validates opts, renders the stub, and writes the file. It refuses to clobber an existing file unless Force is set.

Jump to

Keyboard shortcuts

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