scaffold

package
v1.1.5 Latest Latest
Warning

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

Go to latest
Published: May 26, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package scaffold provides the canonical plugin scaffolding logic shared between the nself CLI (plugin new command) and the standalone new-plugin binary in plugin-sdk-go/devkit.

Both entry points call scaffold.Run with a Params struct; the output is identical so that plugin authors get the same result regardless of whether they have nself installed or use the SDK devkit directly.

Purpose: Core types and all logic functions for plugin scaffold generation.

Template strings are in scaffold_templates_infra.go (infrastructure,
devops, metadata templates) and scaffold_templates_code.go (Go code
templates: main, config, server, server_test).

Inputs: Options struct — name, tier, language, tenancy mode, overrides. Outputs: Result struct — output directory path and list of emitted files. Constraints: Must remain import-compatible with plugin-sdk-go/devkit.

Template strings must live in the _templates_*.go files, not here.

SPORT: cli/internal/plugin/scaffold — decomposed from scaffold.go (T-E2-06).

Index

Constants

This section is empty.

Variables

View Source
var SlugRE = regexp.MustCompile(`^[a-z][a-z0-9-]{0,39}[a-z0-9]$`)

SlugRE is the valid plugin name regexp. A slug must start with a lowercase letter, be at least 2 chars, at most 41 chars total, contain only lowercase letters, digits, and internal hyphens, and must NOT end with a hyphen.

Functions

This section is empty.

Types

type Options

type Options struct {
	// Name is required. Must match SlugRE.
	Name string
	// Tier is "free" or "pro". Default "free".
	Tier string
	// Bundle is the bundle display name (optional for free plugins).
	Bundle string
	// Description defaults to "nSelf <name> plugin."
	Description string
	// Author is optional.
	Author string
	// Category defaults to "custom".
	Category string
	// Language is the plugin language: go, rust, node, static. Default "go".
	Language string
	// MinCLI is the minimum nSelf CLI version required. Default "1.0.9".
	MinCLI string
	// MinSDK is the minimum plugin-sdk-go version required. Default "0.1.0".
	MinSDK string
	// Port is the default listen port. Default 8080.
	Port int
	// OutDir overrides the output directory. Default: ./<name>.
	OutDir string
	// Force allows overwriting an existing directory.
	Force bool
	// Tenancy controls multi-tenant column scaffolding. Default TenancyNone.
	// When empty string it is treated as TenancyNone.
	Tenancy TenancyMode
}

Options configures a scaffold run.

type Params

type Params struct {
	Name        string // plugin slug, e.g. "mywidget"
	PascalName  string // e.g. "Mywidget"
	EnvPrefix   string // e.g. "MYWIDGET" (upper-cased, dashes to underscores)
	RepoBucket  string // "paid" or "free"
	Tier        string // "free" or "pro"
	Bundle      string // bundle display name, e.g. "nClaw" (empty allowed for free)
	Description string
	Author      string
	License     string
	Language    string // "go" (default), "rust", "node", "static"
	MinCLI      string
	MinSDK      string
	Category    string
	Port        int
	Year        int
	Tenancy     TenancyMode // multi-tenant column choice; empty == TenancyNone
}

Params carries all values available inside scaffold templates.

type Result

type Result struct {
	Dir   string
	Files []string
}

Result describes what was emitted.

func Run

func Run(opts Options) (*Result, error)

Run executes the scaffold and returns the result.

type TenancyMode added in v1.1.0

type TenancyMode string

TenancyMode controls which multi-tenant column(s) the scaffold emits. Matches the --tenancy flag and the interactive prompt choices.

const (
	// TenancyNone omits all tenancy columns. Use for plugins with no per-user Postgres tables.
	TenancyNone TenancyMode = "none"
	// TenancyAppIsolation emits source_account_id TEXT NOT NULL DEFAULT 'primary'.
	// Correct for multi-app isolation within one nSelf deploy.
	TenancyAppIsolation TenancyMode = "app-isolation"
	// TenancyCloudTenant emits tenant_id UUID (nullable) + Hasura row filter.
	// Correct for Cloud SaaS where each paying customer is isolated.
	TenancyCloudTenant TenancyMode = "cloud-tenant"
	// TenancyBoth emits both columns. Use when unsure — the developer can remove one later.
	TenancyBoth TenancyMode = "both"
)

Jump to

Keyboard shortcuts

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