generate

package
v0.28.6 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2026 License: MIT Imports: 12 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package generate writes a Surface app's generated files from an explicit description of the app: its name, the modules it is made of (already resolved to Go import paths and page entries, in start order) and the page's app metadata (home view, menu, developer-only views).

It is the library behind `surface generate`, which reads surface.yaml and resolves each module before calling Generate. Another tool may describe an app its own way and call Generate with the result: this package never decides which modules an app has or where they come from.

For an app in appDir of the repository at root, Generate writes:

<appDir>/substrate.yaml           Substrate's manifest; then runs `substrate generate`,
                                  which writes <appDir>/substrate_wiring.go
<appDir>/surface_wiring.go        the modules' blank imports and start order
<appDir>/main.go                  the app's main (app.Main)
<appDir>/webui/embed.go           the embedded page (and webui/dist/.gitkeep)
<root>/web/src/generated/<app>.ts the page's app, module list and app metadata (meta)

The same inputs always give the same bytes, and a file whose content is unchanged is not rewritten.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Generate

func Generate(ctx context.Context, root, appDir string, a App, opts Options) error

Generate writes the app's generated files for the app in appDir (absolute, or relative to root) of the Go module whose go.mod is in root, and runs `substrate generate` unless opts.SkipSubstrate. It checks the app first and writes nothing when it is not valid.

func ValidID

func ValidID(id string) bool

ValidID reports whether id is a valid app or module id.

Types

type App

type App struct {
	// Name is the binary's name: lower case letters, digits and dashes, starting with a letter.
	// Title is how a person reads it ("" = Name).
	Name, Title string
	// Addr is the default listen address ("" = 127.0.0.1:8190).
	Addr string
	// Auth is "" or "off" (one owner, loopback only) or "identity" (people sign in through
	// Substrate's identity module).
	Auth string
	// Log is Substrate's logging block (nil = level info, text format).
	Log map[string]any
	// Modules are the modules compiled in, in start order. At least one; ids are unique.
	Modules []Module
	// Home is the view the page opens on an empty desk ("" = none).
	Home string
	// Menu is the app's menu declaration. Nil means the app declares none, and the page keeps
	// its own defaults.
	Menu *Menu
	// DevOnly are the ids of views shown only in developer mode.
	DevOnly []string
}

App describes the app to generate.

type Menu struct {
	Groups []MenuGroup
	Items  []MenuItem
	Pins   []MenuPin
}

Menu is the app's declaration of its desk menu: groups, where each view goes, and pins.

type MenuGroup struct {
	ID     string `json:"id"`
	Title  string `json:"title"`
	Parent string `json:"parent,omitempty"`
	Order  int    `json:"order"`
}

MenuGroup is a group of the menu. Parent is another group's ID, or "" for a top-level group.

type MenuItem struct {
	View   string `json:"view"`
	Group  string `json:"group,omitempty"`
	Order  int    `json:"order"`
	Hidden bool   `json:"hidden,omitempty"`
	Title  string `json:"title,omitempty"`
}

MenuItem places a view in the menu: in Group (a group's ID, or "" for the top level), at Order, optionally Hidden, optionally under another Title.

type MenuPin struct {
	View  string         `json:"view"`
	Args  map[string]any `json:"args,omitempty"`
	Icon  string         `json:"icon,omitempty"`
	Label string         `json:"label,omitempty"`
}

MenuPin is a pinned entry of the menu: a view opened with Args, drawn with Icon and Label. Args must encode as JSON.

type Module

type Module struct {
	// ID is the module's id: lower case letters, digits and dashes, starting with a letter.
	ID string
	// Import is the module's Go package path, blank-imported by surface_wiring.go.
	Import string
	// Web is the module's page entry, or "" when the module has no views of its own. It is a
	// path relative to the repository root (for example "modules/notes/web/index.tsx"), or a
	// bare package specifier starting with "@" (for example "@surface/modules/notes"), which is
	// imported as it is.
	Web string
}

Module is one module compiled into the app. Every field is resolved by the caller.

type Options

type Options struct {
	// Source names the file the app was described in, in each generated file's header
	// ("" = "surface.yaml").
	Source string
	// Command names the command that generates, in substrate.yaml's header
	// ("" = "surface generate").
	Command string
	// SkipSubstrate skips running `substrate generate` after writing substrate.yaml, for a
	// caller that runs it itself (or a test with no Substrate to run).
	SkipSubstrate bool
	// Stdout and Stderr receive `substrate generate`'s output. Nil discards it; on failure its
	// error output is part of the returned error.
	Stdout, Stderr io.Writer
}

Options are how the files are written, not what is in the app.

Jump to

Keyboard shortcuts

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