scaffold

package
v0.0.89 Latest Latest
Warning

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

Go to latest
Published: May 5, 2024 License: MIT Imports: 23 Imported by: 0

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

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

Functions

func BuildVars

func BuildVars(eng *engine.Engine, args *RWFSArgs, 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) ([]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 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.

Types

type AnyPrompt

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

func (AnyPrompt) IsConfirm

func (p AnyPrompt) IsConfirm() bool

func (AnyPrompt) IsInput

func (p AnyPrompt) IsInput() bool

func (AnyPrompt) IsMultiSelect

func (p AnyPrompt) IsMultiSelect() bool

func (AnyPrompt) IsSelect

func (p AnyPrompt) IsSelect() bool

type AuthEntry

type AuthEntry struct {
	Match regexp.Regexp `yaml:"match"`
	Basic BasicAuth     `yaml:"basic"`
	Token string        `yaml:"token"`
}

type BasicAuth

type BasicAuth struct {
	Username string `yaml:"username"`
	Password string `yaml:"password"`
}

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"`
	Template string `yaml:"template"`
}

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]string, e *engine.Engine) (map[string]any, error)

type ProjectScaffoldFile

type ProjectScaffoldFile struct {
	Skip      []string          `yaml:"skip"`
	Questions []Question        `yaml:"questions"`
	Rewrites  []Rewrite         `yaml:"rewrites"`
	Computed  map[string]string `yaml:"computed"`
	Messages  struct {
		Pre  string `yaml:"pre"`
		Post string `yaml:"post"`
	} `yaml:"messages"`
	Inject   []Injectable `yaml:"inject"`
	Features []Feature    `yaml:"features"`
}

func ReadScaffoldFile

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

type Question

type Question struct {
	Name     string    `yaml:"name"`
	Prompt   AnyPrompt `yaml:"prompt"`
	When     string    `yaml:"when"`
	Required bool      `yaml:"required"`
}

func (Question) ToSurveyQuestion

func (q Question) ToSurveyQuestion(defaults engine.Vars) *survey.Question

type RCValidationError

type RCValidationError struct {
	Key   string
	Cause error
}

type RWFSArgs

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

type RcValidationErrors

type RcValidationErrors []RCValidationError

func (RcValidationErrors) Error

func (e RcValidationErrors) Error() string

type Rewrite

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

type ScaffoldRC

type ScaffoldRC struct {
	// Defaults define a default value for a variable.
	//   name: myproject
	//   git_user: hay-kot
	//
	// These are injected into the template as variables for
	// every scaffold.
	Defaults map[string]string `yaml:"defaults"`

	// Aliases define a alias for a repository.
	// or filepath.
	//
	//   component: https://githublcom/hay-kot/scaffold-go-component
	//   cli: https://github.com/hay-kot/scaffold-go-cli
	Aliases map[string]string `yaml:"aliases"`

	// Shorts define a short name for a repository.
	// the key will be expanded into the value.
	//   gh: https://github.com
	//   gt: https://gitea.com
	//
	// This will allow you to use the short name in the scaffold
	//   gh:myorg/myrepo
	Shorts map[string]string `yaml:"shorts"`

	// Auth defines a list of auth entries that can be used to
	// authenticate with a remote SCM.
	Auth []AuthEntry `yaml:"auth"`
}

func NewScaffoldRC

func NewScaffoldRC(r io.Reader) (*ScaffoldRC, error)

func (*ScaffoldRC) Authenticator

func (rc *ScaffoldRC) Authenticator(pkgurl string) (transport.AuthMethod, bool)

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

Jump to

Keyboard shortcuts

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