Documentation
¶
Overview ¶
Package cli provides command-line interface tools for GoSPA.
Package cli provides the state pruning functionality for GoSPA.
Index ¶
- func Build(config *BuildConfig)
- func BuildAll(config *BuildAllConfig)
- func BuildIslands(config *BuildConfig, summary *BuildSummary) error
- func Clean(config *CleanConfig)
- func CreateProject(name string)
- func CreateProjectWithConfig(config *ProjectConfig) error
- func CreateProjectWithOptions(name string, template string, nonInteractive bool)
- func CreateProjectWithTemplate(name string, template string)
- func Dev(config *DevConfig)
- func DevWithConfig(config *DevConfig) error
- func Doctor(config *DoctorConfig)
- func FindConfigFile() string
- func Generate(config *GenerateConfig)
- func GenerateWithConfig(config *GenerateConfig) error
- func GetBundlerCommand(pm PackageManager) string
- func GetExecuteCommand(pm PackageManager) string
- func GetRunCommand(pm PackageManager) string
- func PrintBanner()
- func Prune(config *PruneConfig)
- func SaveConfig(config *GoSPAConfig, path string) error
- func Serve(config *ServeConfig)
- func ServeWithMultiFormat(config *ServeConfig)
- func StateAnalyze(config *PruneConfig)
- func StateTree(stateFile string, usedPaths []string, jsonOut bool)
- func ValidateProjectName(name string) error
- func Verify(config *VerifyConfig)
- func Watch()
- type BuildAllConfig
- type BuildAllSection
- type BuildConfig
- type BuildSection
- type BuildSummary
- type CleanConfig
- type ColorPrinter
- func (p *ColorPrinter) Bold(text string) string
- func (p *ColorPrinter) Cyan(text string) string
- func (p *ColorPrinter) Dim(text string) string
- func (p *ColorPrinter) Error(format string, args ...interface{})
- func (p *ColorPrinter) Green(text string) string
- func (p *ColorPrinter) Info(format string, args ...interface{})
- func (p *ColorPrinter) ProgressBar(current, total int, label string)
- func (p *ColorPrinter) Red(text string) string
- func (p *ColorPrinter) Step(step int, total int, format string, args ...interface{})
- func (p *ColorPrinter) Subtitle(format string, args ...interface{})
- func (p *ColorPrinter) Success(format string, args ...interface{})
- func (p *ColorPrinter) Title(format string, args ...interface{})
- func (p *ColorPrinter) Warning(format string, args ...interface{})
- func (p *ColorPrinter) Yellow(text string) string
- type DevConfig
- type DevSection
- type DevWatcher
- type DoctorConfig
- type FileEvent
- type FileOp
- type GenerateConfig
- type GenerateSection
- type GoSPAConfig
- type PackageManager
- type PluginConfig
- type ProjectConfig
- type ProjectSection
- type PruneConfig
- type RemoteActionInfo
- type ServeConfig
- type ServeSection
- type Spinner
- type Target
- type TypeScriptField
- type TypeScriptType
- type VerifyConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildIslands ¶ added in v0.1.34
func BuildIslands(config *BuildConfig, summary *BuildSummary) error
BuildIslands builds the islands TypeScript bundle into a single JavaScript file.
func CreateProject ¶
func CreateProject(name string)
CreateProject creates a new GoSPA project with the given name.
func CreateProjectWithConfig ¶
func CreateProjectWithConfig(config *ProjectConfig) error
CreateProjectWithConfig creates a new GoSPA project with custom configuration.
func CreateProjectWithOptions ¶ added in v0.1.33
CreateProjectWithOptions creates a new GoSPA project with custom options.
func CreateProjectWithTemplate ¶ added in v0.1.33
CreateProjectWithTemplate creates a new GoSPA project with the specified template.
func DevWithConfig ¶
DevWithConfig starts the development server with custom configuration.
func Doctor ¶ added in v0.1.30
func Doctor(config *DoctorConfig)
Doctor inspects the current project for common setup issues.
func FindConfigFile ¶ added in v0.1.37
func FindConfigFile() string
FindConfigFile searches for config files in the current directory. Returns the path to the first found config file, or empty string if none found.
func Generate ¶
func Generate(config *GenerateConfig)
Generate generates TypeScript types and routes from Go templates.
func GenerateWithConfig ¶
func GenerateWithConfig(config *GenerateConfig) error
GenerateWithConfig generates code with custom configuration.
func GetBundlerCommand ¶ added in v0.1.36
func GetBundlerCommand(pm PackageManager) string
GetBundlerCommand returns the package manager command for bun-compatible operations. Note: For pnpm and npm, this returns the PM name - you need to use GetExecuteCommand with esbuild for actual bundling since pnpm/npm don't have built-in bundlers. Use BunPM directly with "bun build" for native bundling.
func GetExecuteCommand ¶ added in v0.1.36
func GetExecuteCommand(pm PackageManager) string
GetExecuteCommand returns the "execute" (dlx/x) equivalent for the package manager.
func GetRunCommand ¶ added in v0.1.36
func GetRunCommand(pm PackageManager) string
GetRunCommand returns the command to run a script.
func SaveConfig ¶ added in v0.1.37
func SaveConfig(config *GoSPAConfig, path string) error
SaveConfig saves the gospa configuration to a file.
func Serve ¶ added in v0.1.37
func Serve(config *ServeConfig)
Serve starts a production server to serve static files.
func ServeWithMultiFormat ¶ added in v0.1.37
func ServeWithMultiFormat(config *ServeConfig)
ServeWithMultiFormat serves static files with support for multiple compression formats. It handles Brotli (.br) and gzip (.gz) compressed files when Accept-Encoding includes them.
func StateAnalyze ¶
func StateAnalyze(config *PruneConfig)
StateAnalyze executes the state analysis command.
func ValidateProjectName ¶
ValidateProjectName checks if a project name is valid.
func Verify ¶ added in v0.1.39
func Verify(config *VerifyConfig)
Verify runs strict preflight checks intended for pre-dev and CI gates.
Types ¶
type BuildAllConfig ¶ added in v0.1.37
type BuildAllConfig struct {
Targets []string // Target platforms (e.g., linux/amd64, darwin/arm64)
OutputDir string // Output directory for builds
Compress bool // Compress binaries with tar.gz
Manifest bool // Generate release manifest
Parallel int // Number of parallel builds (0 = number of CPUs)
}
BuildAllConfig holds configuration for multi-platform builds.
type BuildAllSection ¶ added in v0.1.37
type BuildAllSection struct {
Targets []string `yaml:"targets"`
OutputDir string `yaml:"output_dir"`
Compress bool `yaml:"compress"`
Manifest bool `yaml:"manifest"`
Parallel int `yaml:"parallel"`
}
BuildAllSection holds multi-platform build configuration.
type BuildConfig ¶
type BuildConfig struct {
OutputDir string // Output directory
Platform string // Target GOOS
Arch string // Target GOARCH
StaticAssets bool // Copy static assets
Minify bool // Enable minification
Compress bool // Enable gzip/br compression
Env string // Build environment
SourceMap bool // Generate source maps
NoSourceMap bool // Explicitly disable source maps
CGO bool // Enable CGO
LDFlags string // Custom linker flags
Tags string // Build tags (comma-separated)
AssetsDir string // Static assets source directory
NoManifest bool // Skip build manifest generation
Watch bool // Watch mode after build
NoStatic bool // Skip static asset copying
NoCompress bool // Skip compression
}
BuildConfig holds configuration for the production build.
type BuildSection ¶ added in v0.1.37
type BuildSection struct {
Output string `yaml:"output"`
Minify bool `yaml:"minify"`
Compress bool `yaml:"compress"`
SourceMap bool `yaml:"sourcemap"`
CGO bool `yaml:"cgo"`
Env string `yaml:"env"`
AssetsDir string `yaml:"assets_dir"`
LDFlags string `yaml:"ldflags"`
Tags string `yaml:"tags"`
Targets []Target `yaml:"targets"`
}
BuildSection holds build configuration.
type BuildSummary ¶ added in v0.1.30
type BuildSummary struct {
BunPath string
ClientRuntimeBuilt bool
ClientRuntimePath string
GoBinaryPath string
StaticFilesCopied int
CompressedFiles int
}
BuildSummary captures the important outputs from a production build.
func BuildWithConfig ¶
func BuildWithConfig(config *BuildConfig) (*BuildSummary, error)
BuildWithConfig builds the application with custom configuration.
type CleanConfig ¶ added in v0.1.37
type CleanConfig struct {
DryRun bool // Show what would be deleted
NodeModules bool // Include node_modules
Generated bool // Include generated files
Dist bool // Include dist directory
All bool // Clean everything including cache
Cache bool // Clean gospa cache (~/.gospa)
}
CleanConfig holds configuration for the clean command.
type ColorPrinter ¶
type ColorPrinter struct {
// contains filtered or unexported fields
}
ColorPrinter provides colored output utilities
func NewColorPrinter ¶
func NewColorPrinter() *ColorPrinter
NewColorPrinter creates a new color printer
func (*ColorPrinter) Error ¶
func (p *ColorPrinter) Error(format string, args ...interface{})
Error prints a red error message with X mark
func (*ColorPrinter) Green ¶
func (p *ColorPrinter) Green(text string) string
Green returns green text
func (*ColorPrinter) Info ¶
func (p *ColorPrinter) Info(format string, args ...interface{})
Info prints a blue info message
func (*ColorPrinter) ProgressBar ¶
func (p *ColorPrinter) ProgressBar(current, total int, label string)
ProgressBar displays a simple progress bar
func (*ColorPrinter) Step ¶
func (p *ColorPrinter) Step(step int, total int, format string, args ...interface{})
Step prints a step in a process
func (*ColorPrinter) Subtitle ¶
func (p *ColorPrinter) Subtitle(format string, args ...interface{})
Subtitle prints a dimmed subtitle
func (*ColorPrinter) Success ¶
func (p *ColorPrinter) Success(format string, args ...interface{})
Success prints a green success message with checkmark
func (*ColorPrinter) Title ¶
func (p *ColorPrinter) Title(format string, args ...interface{})
Title prints a bold title
func (*ColorPrinter) Warning ¶
func (p *ColorPrinter) Warning(format string, args ...interface{})
Warning prints a yellow warning message
func (*ColorPrinter) Yellow ¶
func (p *ColorPrinter) Yellow(text string) string
Yellow returns yellow text
type DevConfig ¶
type DevConfig struct {
Port int // Server port
Host string // Bind address
RoutesDir string // Routes directory
WatchPaths []string // extra directories to watch in addition to RoutesDir
Open bool // open browser automatically
Verbose bool // verbose logging
NoRestart bool // disable automatic server restart on file changes
Timeout time.Duration // Server start timeout before kill
LogFormat string // Log format: text, json
HMRPort int // HMR WebSocket port (0 = auto)
Proxy string // Proxy API requests to backend
Debounce time.Duration // File change debounce interval
}
DevConfig holds configuration for the development server.
type DevSection ¶ added in v0.1.37
type DevSection struct {
Port int `yaml:"port"`
Host string `yaml:"host"`
Open bool `yaml:"open"`
RoutesDir string `yaml:"routes_dir"`
WatchPaths []string `yaml:"watch_paths"`
Proxy string `yaml:"proxy"`
HMRPort int `yaml:"hmr_port"`
Debounce time.Duration `yaml:"debounce"`
Timeout time.Duration `yaml:"timeout"`
}
DevSection holds development server configuration.
type DevWatcher ¶
type DevWatcher struct {
Events chan FileEvent
Errors chan error
// contains filtered or unexported fields
}
DevWatcher watches files for changes.
func NewDevWatcher ¶
func NewDevWatcher(dirs ...string) *DevWatcher
NewDevWatcher creates a new file watcher with configurable debounce.
func (*DevWatcher) SetDebounce ¶ added in v0.1.37
func (dw *DevWatcher) SetDebounce(d time.Duration)
SetDebounce sets the debounce duration for the watcher.
func (*DevWatcher) Start ¶
func (dw *DevWatcher) Start() error
Start begins watching the configured directories.
type DoctorConfig ¶ added in v0.1.30
type DoctorConfig struct {
RoutesDir string // Routes directory
Fix bool // Auto-fix detected issues
JSONOutput bool // JSON output
Quiet bool // Only show errors
CheckUpdates bool // Check for package updates
Strict bool // Enable strict preflight checks
}
DoctorConfig controls CLI doctor checks.
type GenerateConfig ¶
type GenerateConfig struct {
InputDir string // Input directory
OutputDir string // Output directory
StateFiles []string // State files to process
RouteFiles []string // Route files to process
ComponentType string // Default component type
DevMode bool // Development mode (HMR enabled)
Watch bool // Watch mode
NoTypes bool // Skip TS type generation
NoActions bool // Skip remote action generation
RoutesOnly bool // Only generate routes
Strict bool // Strict type checking
NoTempl bool // Skip templ generate
}
GenerateConfig holds configuration for code generation.
type GenerateSection ¶ added in v0.1.37
type GenerateSection struct {
Output string `yaml:"output"`
Type string `yaml:"type"`
Strict bool `yaml:"strict"`
}
GenerateSection holds code generation configuration.
type GoSPAConfig ¶ added in v0.1.37
type GoSPAConfig struct {
Version string `yaml:"version"`
Project ProjectSection `yaml:"project"`
Dev DevSection `yaml:"dev"`
Build BuildSection `yaml:"build"`
Generate GenerateSection `yaml:"generate"`
Serve ServeSection `yaml:"serve"`
Plugins []PluginConfig `yaml:"plugins"`
BuildAll BuildAllSection `yaml:"build-all"`
}
GoSPAConfig represents the full gospa configuration file format.
func DefaultConfig ¶ added in v0.1.37
func DefaultConfig() *GoSPAConfig
DefaultConfig returns a default configuration.
func LoadConfig ¶ added in v0.1.37
func LoadConfig(path string) (*GoSPAConfig, error)
LoadConfig loads the gospa configuration from file. If no config file is found, returns default config.
func (*GoSPAConfig) MergeWithEnv ¶ added in v0.1.37
func (c *GoSPAConfig) MergeWithEnv()
MergeWithEnv merges config values with environment variables. Environment variables take precedence over config file values.
func (*GoSPAConfig) ToBuildAllConfig ¶ added in v0.1.37
func (c *GoSPAConfig) ToBuildAllConfig() *BuildAllConfig
ToBuildAllConfig converts the config to BuildAllConfig format.
func (*GoSPAConfig) ToBuildConfig ¶ added in v0.1.37
func (c *GoSPAConfig) ToBuildConfig() *BuildConfig
ToBuildConfig converts the config to BuildConfig format.
func (*GoSPAConfig) ToDevConfig ¶ added in v0.1.37
func (c *GoSPAConfig) ToDevConfig() *DevConfig
ToDevConfig converts the config to DevConfig format.
func (*GoSPAConfig) ToGenerateConfig ¶ added in v0.1.37
func (c *GoSPAConfig) ToGenerateConfig() *GenerateConfig
ToGenerateConfig converts the config to GenerateConfig format.
func (*GoSPAConfig) ToServeConfig ¶ added in v0.1.37
func (c *GoSPAConfig) ToServeConfig() *ServeConfig
ToServeConfig converts the config to ServeConfig format.
type PackageManager ¶ added in v0.1.36
type PackageManager string
PackageManager represents a Node.js package manager.
const ( // BunPM is the bun package manager. BunPM PackageManager = "bun" // PnpmPM is the pnpm package manager. PnpmPM PackageManager = "pnpm" // NpmPM is the npm package manager. NpmPM PackageManager = "npm" // NonePM is used when no package manager is found. NonePM PackageManager = "" )
func GetPackageManager ¶ added in v0.1.36
func GetPackageManager() PackageManager
GetPackageManager returns the best available package manager in priority order: bun, pnpm, npm.
func (PackageManager) String ¶ added in v0.1.36
func (pm PackageManager) String() string
type PluginConfig ¶ added in v0.1.37
PluginConfig holds plugin configuration.
type ProjectConfig ¶
type ProjectConfig struct {
Name string
Module string
OutputDir string
WithGit bool
WithDocker bool
Template string
NonInteractive bool
PackageManager string // Package manager to use (bun, pnpm, npm, auto)
}
ProjectConfig holds configuration for a new GoSPA project.
type ProjectSection ¶ added in v0.1.37
ProjectSection holds project-level configuration.
type PruneConfig ¶
type PruneConfig struct {
RootDir string
OutputDir string
ReportFile string
KeepUnused bool
Aggressive bool
Exclude []string
Include []string
DryRun bool
Verbose bool
JSONOutput bool
}
PruneConfig holds configuration for the prune command.
type RemoteActionInfo ¶ added in v0.1.33
RemoteActionInfo holds information about a registered remote action
type ServeConfig ¶ added in v0.1.37
type ServeConfig struct {
Port int // Server port
Host string // Bind address
Dir string // Directory to serve from
HTTPS bool // Enable HTTPS
Cert string // TLS certificate file
Key string // TLS key file
Open bool // Open browser on start
Gzip bool // Enable gzip compression
Brotli bool // Enable brotli compression
Cache bool // Enable cache headers
Headers map[string]string // Custom headers
}
ServeConfig holds configuration for the production server.
type ServeSection ¶ added in v0.1.37
type ServeSection struct {
Port int `yaml:"port"`
Gzip bool `yaml:"gzip"`
Brotli bool `yaml:"brotli"`
Cache bool `yaml:"cache"`
Headers map[string]string `yaml:"headers"`
}
ServeSection holds production server configuration.
type Spinner ¶
type Spinner struct {
// contains filtered or unexported fields
}
Spinner shows a spinning animation
func NewSpinner ¶
func NewSpinner(printer *ColorPrinter, message string) *Spinner
NewSpinner creates a new spinner
type TypeScriptField ¶
TypeScriptField represents a field in a TypeScript type.
type TypeScriptType ¶
type TypeScriptType struct {
Name string
Fields []TypeScriptField
}
TypeScriptType represents a TypeScript type definition.