scaffold

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2025 License: MIT Imports: 24 Imported by: 0

Documentation

Overview

Package scaffold provides a simple way to scaffold a project from a template

Index

Constants

View Source
const (
	HooksDir            = "hooks"
	PostScaffoldScripts = "post_scaffold"
)

Variables

View Source
var ErrInjectMarkerNotFound = errors.New("inject marker not found")

Functions

func BuildVars

func BuildVars(eng *engine.Engine, project *Project, vars engine.Vars) (engine.Vars, error)

BuildVars builds the vars for the engine by setting the provided vars under the "Scaffold" key and adding the project name and computed vars.

func Inject

func Inject(r io.Reader, data string, at string, mode Mode) ([]byte, error)

Inject will read the reader line by line and find the line that contains the string "at". It will then insert the data before that line.

func MergeMaps

func MergeMaps[T any](maps ...map[string]T) map[string]T

MergeMaps merges multiple maps into a single map. If a key is present in multiple maps, the value from the last map will be used.

func QuestionGroupBy added in v0.0.93

func QuestionGroupBy(questions []Question) [][]Question

func RenderRWFS

func RenderRWFS(eng *engine.Engine, args *RWFSArgs, vars engine.Vars) error

RenderRWFS renders a rwfs.RFS to a rwfs.WriteFS by compiling all files in the rwfs.ReadFS and writing the compiled files to the WriteFS.

func TestparseDefaultBool added in v0.0.93

func TestparseDefaultBool(t *testing.T)

func TestparseDefaultString added in v0.0.93

func TestparseDefaultString(t *testing.T)

func TestparseDefaultStrings added in v0.0.93

func TestparseDefaultStrings(t *testing.T)

Types

type AnyPrompt

type AnyPrompt struct {
	Message     *string   `yaml:"message"`
	Description *string   `yaml:"description"`
	Default     any       `yaml:"default"`
	Confirm     *string   `yaml:"confirm"`
	Options     *[]string `yaml:"options"`
	Loop        bool      `yaml:"loop"`
	Multi       bool      `yaml:"multi"`
}

func (AnyPrompt) IsConfirm

func (p AnyPrompt) IsConfirm() bool

func (AnyPrompt) IsInput

func (p AnyPrompt) IsInput() bool

func (AnyPrompt) IsInputLoop added in v0.0.93

func (p AnyPrompt) IsInputLoop() bool

func (AnyPrompt) IsMultiSelect

func (p AnyPrompt) IsMultiSelect() bool

func (AnyPrompt) IsSelect

func (p AnyPrompt) IsSelect() bool

func (AnyPrompt) IsTextInput added in v0.0.93

func (p AnyPrompt) IsTextInput() bool

type Askable added in v0.0.93

type Askable struct {
	Name  string
	Key   string
	Hook  func(vars engine.Vars) error
	Field huh.Field
}

func NewAskable added in v0.0.93

func NewAskable(name string, key string, field huh.Field, fn func(vars engine.Vars) error) *Askable

func (*Askable) String added in v0.0.93

func (a *Askable) String() string

type Delimiters added in v0.6.0

type Delimiters struct {
	Glob  string `yaml:"glob"`
	Left  string `yaml:"left"`
	Right string `yaml:"right"`
}

type Feature

type Feature struct {
	Value string   `yaml:"value"`
	Globs []string `yaml:"globs"`
}

type Injectable

type Injectable struct {
	Name     string `yaml:"name"`
	Path     string `yaml:"path"`
	At       string `yaml:"at"`
	Mode     Mode   `yaml:"mode"`
	Template string `yaml:"template"`
}

type Messages added in v0.0.93

type Messages struct {
	Pre  string `yaml:"pre"`
	Post string `yaml:"post"`
}

type Metadata added in v0.4.0

type Metadata struct {
	MinimumVersion string `yaml:"minimum_version"`
}

func (Metadata) IsCompatible added in v0.4.0

func (m Metadata) IsCompatible(l zerolog.Logger, current string) (bool, error)

type Mode added in v0.0.99

type Mode string
const (
	Before Mode = "before"
	After  Mode = "after"
)

type Options

type Options struct {
	NoClobber bool `yaml:"no_clobber"`
}

type Project

type Project struct {
	RootFS       rwfs.ReadFS
	NameTemplate string
	Name         string
	Conf         *ProjectScaffoldFile
	Options      Options
}

Project structure hold the project templates file system and configuration for rendering the project.

func LoadProject

func LoadProject(fileSys fs.FS, opts Options) (*Project, error)

func (*Project) AskQuestions

func (p *Project) AskQuestions(def map[string]any, e *engine.Engine, theme *huh.Theme) (map[string]any, error)

type ProjectScaffoldFile

type ProjectScaffoldFile struct {
	Metadata   Metadata                  `yaml:"metadata"`
	Skip       []string                  `yaml:"skip"`
	Questions  []Question                `yaml:"questions"`
	Rewrites   []Rewrite                 `yaml:"rewrites"`
	Computed   map[string]string         `yaml:"computed"`
	Messages   Messages                  `yaml:"messages"`
	Inject     []Injectable              `yaml:"inject"`
	Features   []Feature                 `yaml:"features"`
	Presets    map[string]map[string]any `yaml:"presets"`
	Delimiters []Delimiters              `yaml:"delimiters"`
}

func ReadScaffoldFile

func ReadScaffoldFile(reader io.Reader) (*ProjectScaffoldFile, error)

type Question

type Question struct {
	Name     string              `yaml:"name"`
	Group    string              `yaml:"group"`
	Prompt   AnyPrompt           `yaml:"prompt"`
	When     string              `yaml:"when"`
	Required bool                `yaml:"required"`
	Validate validators.Validate `yaml:"validate"`
}

func (Question) Description added in v0.0.93

func (q Question) Description() string

func (Question) Title added in v0.0.93

func (q Question) Title() string

func (Question) ToAskable added in v0.0.93

func (q Question) ToAskable(def any) *Askable

type RWFSArgs

type RWFSArgs struct {
	ReadFS  rwfs.ReadFS
	WriteFS rwfs.WriteFS
	Project *Project
}

type Rewrite

type Rewrite struct {
	From string `yaml:"from"`
	To   string `yaml:"to"`
}

Directories

Path Synopsis
Package pkgs contains functions for parsing remote urls and checking if a directory is a git repository.
Package pkgs contains functions for parsing remote urls and checking if a directory is a git repository.
pkgurl
Package pkgurl contains functions for parsing remote urls
Package pkgurl contains functions for parsing remote urls
Package scaffoldrc contains the runtime configuration for users
Package scaffoldrc contains the runtime configuration for users

Jump to

Keyboard shortcuts

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