scaffold

package
v0.1.0-rc.5 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: Apache-2.0 Imports: 11 Imported by: 1 module, 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 scaffold writes FACET into a project that does not have it: the record layout, the JSON schemas, the specification, the lint suite with its pinned dispatcher, an empty scan filter and the CI workflow.

Index

Constants

View Source
const (
	DispatcherCopy = "tools/facet-lint/facet"
)

The published project workflow. A source tree that keeps the files it publishes in an overlay directory holds it there, and then its own .github/workflows/facet-lint.yml is that tree's CI rather than the one a project gets; a published tree holds it at the usual place.

View Source
const RecordsDir = "docs/facets"

RecordsDir is where the scaffold puts the record layout unless the caller names another directory. Payload paths below it are rewritten to the chosen directory when the files are written.

Variables

View Source
var ErrTarget = errors.New("unusable target")

ErrTarget matches every TargetError.

View Source
var RecordSubdirs = []string{"features", "policies", "assumptions", "data-entities", "schema", "framework"}

RecordSubdirs are the record directories every scaffolded project gets, created even when they stay empty, in the order they are reported.

Functions

func Bundle

func Bundle() []byte

Bundle returns the embedded bundle bytes.

func FindModuleRoot

func FindModuleRoot(dir string) (string, error)

FindModuleRoot walks up from dir to the directory holding go.mod.

func Generate

func Generate(root string) ([]byte, error)

Generate builds the payload bundle from the source tree at root. The bundle is a txtar archive: a comment, then one '-- path --' line per file followed by its exact bytes.

func RegisterFile

func RegisterFile(f File)

RegisterFile adds one file a linked product scaffolds beside the payload, from the product's init. The path is project-relative in the payload's own form, so a file under RecordsDir follows a chosen records directory the way the Core schemas do. Misuse is a build defect, so it panics at start-up rather than surfacing in some project's init.

Types

type File

type File struct {
	Path string
	Data []byte
}

File is one payload entry.

func Payload

func Payload() ([]File, error)

Payload returns the embedded files in the order they are reported.

type Options

type Options struct {
	// Root is the project directory. It is created when missing.
	Root string
	// RecordsDir is the record layout, relative to Root; empty means RecordsDir.
	RecordsDir string
	// DryRun reports what would be written and writes nothing.
	DryRun bool
	// Force replaces files the project already has.
	Force bool
	// Version, when set, is written as the dispatcher's pinned FACET_VERSION
	// default, so a project scaffolded by a release build installs that
	// release. Empty keeps the pin the payload carries.
	Version string
	// Out receives the report.
	Out io.Writer
}

Options select where and how the scaffold writes.

type Result

type Result struct {
	Written int
	Kept    int
}

Result counts the outcome of a run.

func Run

func Run(o Options) (Result, error)

Run scaffolds Options.Root and reports each step to Options.Out. A file the project already has is kept unless Force is set; the report names every file written and every file kept. Nothing is written before the target has been checked, so an unusable target leaves the disk as it was.

@facet: delivery/distribution/project-scaffold @facet-role: primary

type Source

type Source struct {
	// Path is the destination relative to the project root, with the record
	// layout under RecordsDir.
	Path string
	// From is the canonical file relative to the module root. Empty for a
	// file whose content is Literal.
	From string
	// Strip removes the anchor declarations that bind the canonical file to a
	// record of the FACET Core registry. A scaffolded project holds no such
	// record, so a copied anchor would fail its very first lint.
	Strip stripMode
	// Literal is the content of a file that has no canonical source because
	// its content is a decision about the project rather than a copy.
	Literal []byte
}

Source is one file of the payload: where it lands in a project, and where its bytes come from in the FACET Core source tree.

func Sources

func Sources(root string) ([]Source, error)

Sources lists the payload in the order the scaffold reports it, read from the source tree rooted at root (the directory holding go.mod).

type TargetError

type TargetError struct{ Reason string }

TargetError is a target the scaffold cannot write into at all. Its message is the reason alone, ready to be shown to the person who named the target.

func (*TargetError) Error

func (e *TargetError) Error() string

func (*TargetError) Is

func (e *TargetError) Is(target error) bool

Jump to

Keyboard shortcuts

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