cli

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2026 License: MIT Imports: 27 Imported by: 0

Documentation

Overview

Package cli holds the commands of the avero binary, S14. The command in cmd/avero is a thin wrapper, so a test drives the commands with no process.

Index

Constants

View Source
const (
	// OpenAPIFile is the description that `avero build` writes.
	OpenAPIFile = "openapi.json"
	// OpenAPIConfig is the configuration of the generator of the front end.
	OpenAPIConfig = "openapi-ts.config.ts"
)

The names that the description of the API carries.

View Source
const DrelConfig = "drel.yaml"

DrelConfig is the file that states the models and the migrations of each feature slice.

View Source
const EnvFile = ".env"

EnvFile is the file that a person writes beside the application. `avero dev` reads it, so the loop needs no export in the shell.

View Source
const ProjectFile = "avero.json"

ProjectFile is the file that states the shape of an application and the entry points of its assets. `avero new` writes it.

Variables

View Source
var FrontEnd = map[string][]Module{

	scaffold.ShapeSSR: {
		{"datastar", "https://cdn.jsdelivr.net/gh/starfederation/datastar@v1.0.3/bundles/datastar.js"},
	},
}

FrontEnd holds the modules that each shape vendors. `avero js pin` fetches each one as a bundled ES module and records its address and its hash in avero.lock, so a later build needs no network and no Node.js. See DX-9.

The spa shape vendors nothing, because Vite and npm own its front end.

View Source
var Version = "dev"

Version is the version of the binary. The release build sets it.

Functions

func BuildAssets added in v0.2.0

func BuildAssets(ctx context.Context, dir string, project *Project, minify bool, s Streams) error

BuildAssets builds the front end of the application.

A project with an external bundler reads its dependencies first, so one command builds an application that a person just wrote.

func Describe added in v0.2.0

func Describe(ctx context.Context, dir string, project *Project, s Streams) error

Describe writes the description of the API and the client of the front end.

The Go handlers state the routes, the input types and the answers. The description states the same, and the generator of the front end reads it, so one change of a handler reaches the types of the front end.

func Drel added in v0.2.0

func Drel(ctx context.Context, dir string) error

Drel runs the drel generator when the application states its models.

The application carries the generator as a tool of its go.mod, so `go tool drel` needs no second installation. drel writes the columns, the repository and the migration set of each model.

func FirstMigration added in v0.2.0

func FirstMigration(ctx context.Context, dir, shape string, _ Streams) error

FirstMigration writes the migration of the feature slice that the shape carries.

drel reads the model and writes the difference, so the SQL and the model can never disagree. The scaffolder writes no SQL of its own.

func GenerateCheck

func GenerateCheck(dir string) error

GenerateCheck proves that every generated file of the application is current. It runs in this process, so the application needs no dependency on the avero binary. The MCP server calls the same function. See S16.

func Install added in v0.2.0

func Install(ctx context.Context, dir string, project *Project, s Streams) error

Install reads the dependencies of an external bundler.

It runs one time: a directory that already holds node_modules needs no second read.

func Run

func Run(ctx context.Context, s Streams, args []string) int

Run performs one command and returns the exit code of the process.

func Slice

func Slice(ctx context.Context, dir, name string) (written []string, registered bool, err error)

Slice writes one feature slice, registers it and writes the generated files. The MCP tool scaffold_slice calls it, so an agent and a person write the same files. See the SDD, S16.

func SliceMigration added in v0.2.0

func SliceMigration(ctx context.Context, dir, pkg string) error

SliceMigration writes the first migration of one slice, then runs the drel generator again, so the binary carries the new migration set.

func Templ added in v0.2.0

func Templ(ctx context.Context, dir string) error

Templ runs the templ generator when the application holds a .templ file.

The application carries the generator as a tool of its go.mod, so `go tool templ` needs no second installation. See the SDD, S15.

func Vendor added in v0.2.0

func Vendor(ctx context.Context, dir, shape string, s Streams) error

Vendor fetches the front end modules of a shape.

Types

type Module added in v0.2.0

type Module struct {
	// Name is the specifier that the source imports.
	Name string
	// URL is the address of the bundled ES module.
	URL string
}

Module is one front end module that a shape vendors.

type Project

type Project struct {
	// Name is the name of the application.
	Name string `json:"name"`
	// Shape is ssr, spa or api.
	Shape string `json:"shape"`
	// Hypermedia is datastar or htmx. An api holds none.
	Hypermedia string `json:"hypermedia,omitempty"`
	// Assets states the asset pipeline.
	Assets ProjectAssets `json:"assets"`
	// Migrations is the directory that holds the migration files.
	Migrations string `json:"migrations"`
}

Project is the content of avero.json.

func LoadProject

func LoadProject(dir string) (*Project, error)

LoadProject reads avero.json from dir.

An absent file gives the defaults, so a command works in a directory that a person wrote by hand. A file that exists states the whole asset pipeline: a member that it does not name is empty, so a project that names no Tailwind input runs no Tailwind.

func (*Project) Save

func (p *Project) Save(dir string) error

Save writes avero.json into dir.

type ProjectAssets

type ProjectAssets struct {
	// Entries names each entry point, relative to the assets directory.
	Entries []string `json:"entries"`
	// Tier is bundled, node or external.
	Tier string `json:"tier,omitempty"`
	// Command runs the external bundler of tier 2.
	Command []string `json:"command,omitempty"`
	// Dir is the directory of the external bundler, relative to the
	// application. An empty value runs it in the application directory.
	Dir string `json:"dir,omitempty"`
	// Manifest states whether the bundler writes the manifest of Avero. A
	// bundler that writes its own index document, such as Vite, writes none,
	// and the application serves the build with assets.SPA.
	Manifest *bool `json:"manifest,omitempty"`
	// Tailwind states the stylesheet and the pinned version. An empty input
	// runs no Tailwind.
	Tailwind ProjectTailwind `json:"tailwind"`
}

ProjectAssets states the asset pipeline of one application.

type ProjectTailwind

type ProjectTailwind struct {
	// Input is the stylesheet that Tailwind reads.
	Input string `json:"input,omitempty"`
	// Version is the pinned release of the standalone binary.
	Version string `json:"version,omitempty"`
	// Asset is the name that the manifest records.
	Asset string `json:"asset,omitempty"`
}

ProjectTailwind states the Tailwind build.

type Streams

type Streams struct {
	// Out receives the result of a command.
	Out io.Writer
	// Err receives a fault.
	Err io.Writer
	// In carries the requests of `avero mcp`. A nil value reads the standard
	// input.
	In io.Reader
	// Dir is the working directory. An empty value is the process
	// directory.
	Dir string
}

Streams holds the input and the output of one run.

Jump to

Keyboard shortcuts

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