scaffold

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package scaffold writes the files of a new Backyard project (`backyard init` and the MCP tool backyard_init) and provides SafeJoin, the path guard used whenever the CLI writes files whose names come from elsewhere (templates, `backyard pull`).

Index

Constants

This section is empty.

Variables

View Source
var Agents = []string{"claude", "codex", "cursor", "copilot"}

Agents are the agent integrations `backyard init --agents` accepts.

Functions

func ParseAgents

func ParseAgents(list []string) ([]string, error)

ParseAgents splits a comma-separated agent list, validating each name.

func SafeJoin

func SafeJoin(root, rel string) (string, error)

SafeJoin joins a "/"-separated relative path onto root, rejecting absolute paths, ".." segments, backslashes, drive letters, and paths whose existing parent directories inside root are symlinks or files (which could redirect writes outside root). An existing symlink as the final element is rejected as well.

func WriteFileAtomic

func WriteFileAtomic(path string, data []byte, perm fs.FileMode) error

WriteFileAtomic writes data to a temporary file next to path and renames it into place (replacing, never following, an existing symlink).

Types

type Options

type Options struct {
	// Dir is the project directory (created when missing).
	Dir string
	// Site is the site name (validated against config.DefaultReserved).
	Site string
	// Server is the hub URL recorded in generated docs ("" when unknown).
	Server string
	// BaseDomain and URLMode describe Server when known (its /info), so
	// the docs name the exact site URL (templates.InitOptions).
	BaseDomain string
	URLMode    string
	// Agents selects agent files (default: the templates' default).
	Agents []string
	// Template is the template name (default: the templates' default).
	Template string
	// Force overwrites existing files.
	Force bool
	// Render renders the files (default templates.Render).
	Render Renderer
}

Options configure Init.

type Renderer

type Renderer func(templates.InitOptions) (map[string][]byte, error)

Renderer renders the files of a new project (templates.Render).

type Result

type Result struct {
	Dir         string   `json:"dir"`
	Site        string   `json:"site,omitempty"`
	Created     []string `json:"created"`
	Overwritten []string `json:"overwritten"`
	Skipped     []string `json:"skipped"`
}

Result reports what Init or Write did. Paths are "/"-separated and relative to Dir.

func Init

func Init(o Options) (*Result, error)

Init validates the site name, renders the project files and writes them to o.Dir without overwriting existing files unless o.Force.

func Write

func Write(dir string, files map[string][]byte, force bool) (*Result, error)

Write writes files (keyed by "/"-separated relative path) under dir, creating directories as needed. Existing files are skipped unless force. Paths escaping dir, or crossing a symlink inside it, are rejected before anything is written.

Jump to

Keyboard shortcuts

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