scaffold

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package scaffold generates a new Puzzle application from an embedded template tree (see templates/). It backs `puzzle init`: it validates the requested app name (it becomes an npm package name) and template, refuses to write into a non-empty directory, and copies the template's files with the __APP_NAME__ placeholder substituted.

Templates are real files under templates/<name>/ embedded with go:embed (all: so dotfiles like .gitignore are included). Adding a template is a matter of dropping a new subtree in; no Go changes are needed beyond registering its name in Templates.

Index

Constants

View Source
const DefaultTemplate = "default"

DefaultTemplate is used when --template is not given.

Variables

View Source
var Templates = []string{"default", "todos"}

Templates lists the template names `puzzle init` accepts, in menu order. The first entry is the default.

Functions

func ValidTemplate

func ValidTemplate(name string) bool

ValidTemplate reports whether name is a known template.

func ValidateName

func ValidateName(name string) error

ValidateName reports whether name is an acceptable app / npm package name.

func WriteJSConfig

func WriteJSConfig(dir string) ([]string, error)

WriteJSConfig writes the editor-only jsconfig.json into an already scaffolded app directory, wiring the '@' alias for JS apps (SPEC §40, D75). Like WriteTypeScriptConfig it only drops a config file — no user JS is rewritten (D3) — and it refuses to overwrite an existing jsconfig.json.

func WriteTypeScriptConfig

func WriteTypeScriptConfig(dir string) ([]string, error)

WriteTypeScriptConfig writes a strict/noEmit tsconfig.json into an already scaffolded app directory (v1.22, D54), backing `puzzle init --typescript`. It returns the created files as slash paths relative to dir, and is a no-op-safe add-on: it never rewrites user JS, only drops the config. It refuses to overwrite an existing tsconfig.json.

Types

type Result

type Result struct {
	// Dir is the absolute path of the created app directory.
	Dir string
	// Files are the created files, as slash paths relative to Dir, sorted.
	Files []string
}

Result reports what Create produced.

func Create

func Create(parentDir, appName, template string) (*Result, error)

Create scaffolds template into parentDir/appName and returns what it wrote.

  • parentDir defaults to the current directory when empty.
  • The target dir may not exist, or exist and be empty; a non-empty target is refused.
  • appName is validated (npm package name); template must be known.

Jump to

Keyboard shortcuts

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