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 ¶
const DefaultAddr = "127.0.0.1:8190"
DefaultAddr is the listen address of an app that names none.
Variables ¶
This section is empty.
Functions ¶
func Generate ¶
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 ModulePath ¶ added in v0.28.8
ModulePath is the module path in root's go.mod.
func Normalize ¶ added in v0.28.8
Normalize checks a and fills its defaults (Title, Addr; Auth "off" becomes ""), as Generate does first. It needs only the modules' ids, not their resolution: a caller that resolves modules itself (surface generate) calls it before using an id, then fills Import and Web. Generate also refuses a module with no Import. Normalizing twice changes nothing.
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 ¶
Menu is the app's declaration of its desk menu: groups, where each view goes, and pins.
A declared menu is the whole menu. It replaces the page's built-in groups (the page's DEFAULT_NAV_GROUPS: workspace, knowledge, operations, previews, system and their subgroups), which apply only to an app that declares no menu; so a group an item or a group's Parent names must be one of Groups, built-in ids included. A view the declaration does not place is not in the menu (it keeps its palette command), unless its module's View.Group hint names a declared group. Generate refuses an item in an undeclared group, a group whose parent is not declared, and groups whose parents make a cycle.
type MenuGroup ¶
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 ¶
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 ¶
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.