scaffold

package
v0.4.0 Latest Latest
Warning

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

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

Documentation

Overview

Package scaffold writes a new Avero application, S14.

One template set holds the files that every shape needs, and one set holds the files of each shape: ssr, spa and api. The scaffolder writes plain Go, so a person can read every file, change it and delete it. See design rule 4.

Index

Constants

View Source
const (
	// ShapeSSR is a server rendered application.
	ShapeSSR = "ssr"
	// ShapeSPA is an application with an embedded single page front end.
	ShapeSPA = "spa"
	// ShapeAPI is a JSON service.
	ShapeAPI = "api"
)

The shapes that the scaffolder writes.

View Source
const (
	// Datastar is the default adapter.
	Datastar = "datastar"
	// Htmx is the other adapter.
	Htmx = "htmx"
)

The hypermedia adapters that a shape can carry.

View Source
const (
	// DefaultGoVersion is the version line of go.mod.
	DefaultGoVersion = "1.26.2"
	// DefaultTemplVersion is the version of the templ generator. The ssr
	// shape writes its pages as .templ files, and the generator writes the
	// Go file of each one.
	DefaultTemplVersion = "v0.3.1020"
	// DefaultDrelVersion is the version of drel. Every shape states its
	// models with it, and its generator writes the repositories and the
	// migrations.
	DefaultDrelVersion = "v0.7.1"
)

The versions that go.mod carries when the caller names none.

View Source
const DrelConfig = "drel.yaml"

DrelConfig is the name of the drel configuration file. drel reads the model package of each slice from its modules block.

Variables

This section is empty.

Functions

func AveroVersion added in v0.2.3

func AveroVersion() string

AveroVersion returns the version of Avero that a new application requires.

The binary reads its own version. A release therefore writes the version that carries these templates, and a constant that a person must raise after each tag is gone.

A build from the source names no version, and the answer is empty. go.mod then carries no line for Avero, and `go mod tidy` reads the newest release, or the directory that a replace names. `avero new` runs the command, so the application holds a version either way.

func Layout added in v0.4.0

func Layout(name string) ([]byte, error)

Layout returns the layout that the ssr scaffold writes for an application of this name. `avero ui add` compares a file against it, so it patches a layout that a person did not change and it changes no other layout.

func ModulePath

func ModulePath(dir string) (string, error)

ModulePath returns the module path that go.mod names.

func RegisterSlice

func RegisterSlice(dir, module, pkg string) (bool, error)

RegisterSlice adds the feature to wire.go: the import and the module in the call to avero.Modules. It reports whether it changed the file.

It changes nothing when it does not find the two places, so it never breaks a wiring that a person wrote by hand. The caller then states the two lines to write.

func Write

func Write(opts Options) ([]string, error)

Write writes one application and returns the files that it wrote, in order.

It refuses a directory that already holds files, so it never writes over the work of a person.

func WriteSlice

func WriteSlice(opts SliceOptions) ([]string, error)

WriteSlice writes one feature slice and its migration. It returns the files that it wrote, in order.

`avero slice` calls it, and the MCP tool scaffold_slice calls the same function, so an agent and a person write the same files. See the SDD, S16.

func WriteStarterAssets added in v0.2.0

func WriteStarterAssets(dir, shape string) ([]string, error)

WriteStarterAssets writes the output directory of the assets of an application that already exists.

A clone of a repository holds no built asset, because an application ignores its output directory. The command that runs an example calls this function, so the embedded file system holds a document before the first build.

Types

type Fault

type Fault struct {
	// Message states the fault.
	Message string `json:"message"`
	// Repair states what to do. It is one sentence.
	Repair string `json:"repair"`
	// Command names the command that a person ran, such as `avero slice`. An
	// empty value names `avero new`. See DX-6.
	Command string `json:"command,omitempty"`
}

Fault is one scaffolder fault. It states what went wrong and states the repair in one sentence. See DX-7.

func (*Fault) Error

func (f *Fault) Error() string

Error returns the command, the message and the repair.

type Options

type Options struct {
	// Name is the name of the application. It becomes the directory, the
	// module path and the binary.
	Name string
	// Dir is the directory that receives the files. An empty value is the
	// name inside the working directory.
	Dir string
	// Shape is ssr, spa or api.
	Shape string
	// Hypermedia is datastar or htmx. An api shape carries none.
	Hypermedia string
	// Module is the module path. An empty value is the name.
	Module string
	// AveroVersion is the version of the host that go.mod requires.
	AveroVersion string
	// TemplVersion is the version of the templ generator that an ssr
	// application requires.
	TemplVersion string
	// DrelVersion is the version of drel that an application requires.
	DrelVersion string
	// Replace points the module at a local copy of Avero. A test and the
	// gate of this repository set it. An empty value writes no replace
	// directive.
	Replace string
	// GoVersion is the version line of go.mod.
	GoVersion string
}

Options states one application.

type SliceOptions

type SliceOptions struct {
	// Name is the name of the feature, such as comment or order.
	Name string
	// Dir is the root of the application.
	Dir string
	// Module is the module path of the application. An empty value reads
	// go.mod.
	Module string
}

SliceOptions states one feature slice.

Jump to

Keyboard shortcuts

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