scaffold

package
v0.11.4 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2026 License: BSD-3-Clause Imports: 15 Imported by: 0

Documentation

Overview

Package scaffold handles file generation and scaffolding for WebKit projects.

It provides a Generator interface for creating files from templates, JSON, YAML, and raw bytes with support for scaffold mode (don't overwrite) and generate mode (always overwrite). All generated files are tracked in the manifest for drift detection.

Index

Constants

View Source
const WebKitNotice = "Code generated by webkit; DO NOT EDIT."

WebKitNotice is the notice outputted to all generated files within WebKit.

Variables

This section is empty.

Functions

This section is empty.

Types

type FileGenerator

type FileGenerator struct {
	Printer *printer.Console
	// contains filtered or unexported fields
}

FileGenerator handles file generation on a given filesystem.

func New

func New(fs afero.Fs, manifest *manifest.Tracker, printer *printer.Console) *FileGenerator

New creates a new FileGenerator with the provided afero.Fs.

func (FileGenerator) Bytes

func (f FileGenerator) Bytes(path string, data []byte, opts ...Option) error

Bytes writes bytes to the filesystem and ensure directories exist.

func (FileGenerator) Code added in v0.0.3

func (f FileGenerator) Code(path string, content string, opts ...Option) error

Code writes Go code to a file with the given mode. The content should be valid Go code and will have the WebKit notice prepended.

func (FileGenerator) Copy

func (f FileGenerator) Copy(from, to string, opts ...Option) error

Copy simply copies a file to the destination using the scaffolder.

func (FileGenerator) CopyFromEmbed

func (f FileGenerator) CopyFromEmbed(efs embed.FS, from, to string, opts ...Option) error

CopyFromEmbed copies a file from an embedded FS to the generator's FS.

func (FileGenerator) JSON

func (f FileGenerator) JSON(path string, content any, opts ...Option) error

JSON writes JSON content with the given mode.

func (FileGenerator) Template

func (f FileGenerator) Template(path string, tpl *template.Template, data any, opts ...Option) error

Template writes a template file with the given mode.

func (FileGenerator) YAML

func (f FileGenerator) YAML(path string, content any, opts ...Option) error

YAML writes YAML content with the given mode.

type Generator

type Generator interface {
	Bytes(path string, data []byte, opts ...Option) error
	Copy(from, to string, opts ...Option) error
	CopyFromEmbed(efs embed.FS, from, to string, opts ...Option) error
	Template(path string, tpl *template.Template, data any, opts ...Option) error
	JSON(path string, content any, opts ...Option) error
	YAML(path string, content any, opts ...Option) error
	Code(path string, content string, opts ...Option) error
}

Generator is used for scaffolding files to a WebKit project.

type Option

type Option func(*writeOptions)

Option is a function that configures write options

func WithScaffoldMode

func WithScaffoldMode() Option

WithScaffoldMode sets the write mode for the operation

func WithTracking

func WithTracking(source string) Option

WithTracking adds generators and sources to each file so it can be tracked in the manifest.

func WithoutNotice

func WithoutNotice() Option

WithoutNotice disables the standard "Generated by WebKit" notice.

type WriteMode

type WriteMode int

WriteMode determines how files are written

const (
	// ModeGenerate always writes the file, overwriting if it exists
	ModeGenerate WriteMode = iota
	// ModeScaffold only writes if the file doesn't exist
	ModeScaffold
)

Jump to

Keyboard shortcuts

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