generatecmd

package
v0.1.21 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2026 License: Apache-2.0 Imports: 59 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FileWriter

func FileWriter(fileName string, contents []byte) error

func Run

func Run(ctx context.Context, stdout, stderr io.Writer, args []string) (err error)

Types

type ArgumentError

type ArgumentError struct {
	Message string
}

func (*ArgumentError) Code

func (a *ArgumentError) Code() int

func (*ArgumentError) Error

func (e *ArgumentError) Error() string

type Arguments

type Arguments struct {
	FileName                        string
	FileWriter                      FileWriterFunc
	Path                            string
	Check                           bool
	Watch                           bool
	WatchPattern                    *regexp.Regexp
	IgnorePattern                   *regexp.Regexp
	OpenBrowser                     bool
	Command                         string
	ProxyBind                       string
	ProxyPort                       int
	Proxy                           string
	ProxyTLSCrt                     string
	ProxyTLSKey                     string
	NotifyProxy                     bool
	WorkerCount                     int
	GenerateSourceMapVisualisations bool
	IncludeVersion                  bool
	IncludeTimestamp                bool
	// PPROFPort is the port to run the pprof server on.
	PPROFPort         int
	KeepOrphanedFiles bool
	Lazy              bool
	// Cache enables the on-disk build cache (D6). Modes whose output is
	// not a pure function of source, config, and bindings bypass it
	// regardless.
	Cache bool
	// SourceDirs are the resolved template source directories to walk.
	SourceDirs []string
	// Config is the resolved project configuration
	// (flag > ghtmx.json > default).
	Config config.Config
}

func NewArguments

func NewArguments(stdout, stderr io.Writer, args []string) (cmdArgs Arguments, log *slog.Logger, help bool, err error)

type FSEventHandler

type FSEventHandler struct {
	Log *slog.Logger

	Errors []error
	// contains filtered or unexported fields
}

func NewFSEventHandler

func NewFSEventHandler(
	log *slog.Logger,
	dir string,
	devMode bool,
	genOpts []generator.GenerateOpt,
	genSourceMapVis bool,
	keepOrphanedFiles bool,
	fileWriter FileWriterFunc,
	lazy bool,
	options ...FSEventHandlerOption,
) *FSEventHandler

func (*FSEventHandler) HandleDependent

func (h *FSEventHandler) HandleDependent(ctx context.Context, fileName string) (GenerateResult, error)

HandleDependent re-processes a unit invalidated by another file's change (FR-061 tier two). The unit's own mtime has not advanced, so its freshness gate is reset first — a plain HandleEvent would skip it.

func (*FSEventHandler) HandleEvent

func (h *FSEventHandler) HandleEvent(ctx context.Context, event fsnotify.Event) (result GenerateResult, err error)

func (*FSEventHandler) PhaseTimings

func (h *FSEventHandler) PhaseTimings() (parse, analyze, emit time.Duration)

PhaseTimings reports cumulative wall time spent in each per-file phase across all workers (NFR-001 verbose attribution). Concurrent workers overlap, so sums can exceed elapsed wall time; per-file lock waits are attributed to no phase, so under contention the sum can also understate a file's wall time.

func (*FSEventHandler) UpdateRouteBindings

func (h *FSEventHandler) UpdateRouteBindings(table *routes.Table, constructors map[string]central.Constructor)

UpdateRouteBindings swaps the route table and constructor naming after a watch-mode re-discovery (FR-061 tier one): analysis of subsequent events resolves against the new state.

type FSEventHandlerOption

type FSEventHandlerOption func(*FSEventHandler)

FSEventHandlerOption configures optional event handler behavior.

func WithAttributeValidation

func WithAttributeValidation(surface *htmxsurface.Surface, severityOverrides map[string]diag.Severity) FSEventHandlerOption

WithAttributeValidation enables hx-* attribute validation against the surface for the configured htmx version (FR-024, FR-041, FR-044). Error-level diagnostics fail the file's generation; warnings are logged.

func WithBuildCache

func WithBuildCache(store *buildcache.Store) FSEventHandlerOption

WithBuildCache serves unchanged units from the on-disk build cache (D6, NFR-001). The caller only enables it in modes whose output is a pure function of source content, configuration, and binding state.

func WithCentralFile

func WithCentralFile(absPath string) FSEventHandlerOption

WithCentralFile marks the central generated package's file so the event handler never treats it as an orphaned template output.

func WithGeneratedSuffix

func WithGeneratedSuffix(suffix string) FSEventHandlerOption

WithGeneratedSuffix sets the file-name suffix that replaces the template extension on generated Go files (config generatedSuffix, default "_ghtmx.go").

func WithRouteBindings

func WithRouteBindings(table *routes.Table, modulePath, generatedPkgName string, constructors map[string]central.Constructor) FSEventHandlerOption

WithRouteBindings enables route-aware hx-* binding resolution (FR-020, FR-022) against the discovered route table. modulePath is the module's import path, used to derive each template's package path for bare handler identifiers; generatedPkgName is the central generated package's name.

func WithSetAnalysis

func WithSetAnalysis(sa *analyzer.SetAnalysis) FSEventHandlerOption

WithSetAnalysis attaches the whole-compiled-set collector for the dangling-target and unreachable-route checks (FR-042, FR-043).

func WithSeverityOverrides

func WithSeverityOverrides(overrides map[string]diag.Severity) FSEventHandlerOption

WithSeverityOverrides applies the configured per-check severities to diagnostics the handler emits itself (currently GHTMX-W0301), independent of whether attribute validation loaded.

func WithStaleDiagnostics

func WithStaleDiagnostics(enabled bool) FSEventHandlerOption

WithStaleDiagnostics controls the in-generate GHTMX-W0301 report. Check mode disables it: the check writer writes nothing, so "has been regenerated" would be false — check mode reports drift itself.

func WithTemplateExtension added in v0.1.3

func WithTemplateExtension(ext string) FSEventHandlerOption

WithTemplateExtension sets the extension templates are written with (config templateExtension, default ".ghtmx"). It decides what the watcher treats as a template and, critically, which source file the orphan check looks for: with the wrong extension every generated file looks orphaned and is deleted immediately after being written.

type FatalError

type FatalError struct {
	Err error
}

func (FatalError) As

func (e FatalError) As(target any) bool

func (FatalError) Error

func (e FatalError) Error() string

func (FatalError) Is

func (e FatalError) Is(target error) bool

func (FatalError) Unwrap

func (e FatalError) Unwrap() error

type FileWriterFunc

type FileWriterFunc func(name string, contents []byte) error

func NewCheckWriter

func NewCheckWriter() (writer FileWriterFunc, getChanged func() []string)

NewCheckWriter returns a FileWriterFunc that compares generated output against existing files without writing, and a function to retrieve the list of files that differ.

func WriterFileWriter

func WriterFileWriter(w io.Writer) FileWriterFunc

type Generate

type Generate struct {
	Log        *slog.Logger
	Args       Arguments
	ShouldSkip func(string) bool
	// contains filtered or unexported fields
}

func NewGenerate

func NewGenerate(log *slog.Logger, args Arguments) (g *Generate, err error)

func (Generate) Run

func (cmd Generate) Run(ctx context.Context) (err error)

type GenerateResult

type GenerateResult struct {
	// GoFileWritten indicates that the generated Go file was written because its content changed.
	GoFileWritten bool
	// WatchedFileUpdated indicates that a file matching the watch pattern was updated.
	WatchedFileUpdated bool
	// TemplFileTextUpdated indicates that text literals were updated.
	TemplFileTextUpdated bool
	// TemplFileGoUpdated indicates that Go expressions were updated.
	TemplFileGoUpdated bool
	// GoSourceUpdated indicates that a hand-written Go source file was
	// updated: route registrations may have changed (FR-061 tier one).
	GoSourceUpdated bool
}

type GenerationEvent

type GenerationEvent struct {
	Event                fsnotify.Event
	GoFileWritten        bool
	WatchedFileUpdated   bool
	TemplFileTextUpdated bool
	TemplFileGoUpdated   bool
	GoSourceUpdated      bool
	// Errors counts failed regenerations in this event: errors coalesce
	// into their own batch, so gating attributes them to the change that
	// caused them, never to the fix that follows (FR-063).
	Errors int
}

Directories

Path Synopsis
run
testprogram command

Jump to

Keyboard shortcuts

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