manifest

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2025 License: BSD-3-Clause Imports: 15 Imported by: 0

Documentation

Overview

Package manifest tracks WebKit-generated files for drift detection and cleanup.

It maintains a manifest of all generated files with their source, generator, and content hashes. This enables detecting manual changes (drift) and removing orphaned files when configuration changes.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoManifest = fmt.Errorf("no manifest found")

ErrNoManifest is returned by Load() when there hasen't been a manifest generated yet.

View Source
var Path = filepath.Join(".webkit", "manifest.json")

Path defines the filepath where the manifest resides.

Functions

func Cleanup

func Cleanup(fs afero.Fs, old, new *Manifest, console *printer.Console) error

Cleanup removes files that are no longer needed by WebKit by comparing the old and new manifests.

func HashContent

func HashContent(data []byte) string

HashContent generates a SHA256 hash of the provided data. Used to detect if file contents have changed since generation.

func SourceApp

func SourceApp(name string) string

SourceApp returns a namespaced identifier for application sources. Format: "app:<name>"

func SourceProject

func SourceProject() string

SourceProject returns the identifier string for the project-level manifest source. Used for base files with nothing attached.

func SourceResource

func SourceResource(name string) string

SourceResource returns a namespaced identifier for resource sources. Format: "resource:<name>".

Types

type CallerInfo

type CallerInfo struct {
	Package  string // e.g. "env"
	Function string // e.g. "Scaffold"
	File     string // e.g. "/path/to/env.go"
	Line     int    // e.g. 42
}

CallerInfo holds metadata about the detected caller.

func Caller

func Caller() CallerInfo

Caller returns information about the first exported (public) function in the call stack outside of runtime/scaffold packages.

type DriftEntry

type DriftEntry struct {
	Path      string      // File path
	Type      DriftReason // Type of drift
	Source    string      // What in app.json caused this
	Generator string      // Which generator created it
}

DriftEntry contains information about a single drifted file

func DetectDrift

func DetectDrift(actualFS, expectedFS afero.Fs) ([]DriftEntry, error)

DetectDrift compares actual files on disk against what should be generated. It detects both manual modifications and source drift (app.json changes).

actualFS: The real filesystem expectedFS: In-memory filesystem with freshly generated files from current app.json

Returns all drift: manual edits, outdated files, missing files, and orphaned files.

type DriftReason

type DriftReason int

DriftReason represents the kind of drift detected

const (
	DriftReasonModified DriftReason = iota // File was manually edited
	DriftReasonDeleted                     // File should be removed
	DriftReasonOutdated                    // app.json changed, needs regen
	DriftReasonNew                         // File should exist but doesn't
)

DriftReason constants.

func (DriftReason) FilterEntries

func (d DriftReason) FilterEntries(filtered []DriftEntry) []DriftEntry

FilterEntries plucks entries by the selected DriftReason.

func (DriftReason) String

func (d DriftReason) String() string

String implements fmt.Stringer on the DriftReason.

type FileEntry

type FileEntry struct {
	Path         string    `json:"path"`         // Relative path to the generated file
	Generator    string    `json:"generator"`    // e.g. "cicd.BackupWorkflow", "files.PackageJSON"
	Source       string    `json:"source"`       // What in app.json caused this? e.g., "resource:postgres-prod"
	Hash         string    `json:"hash"`         // SHA256 of content for drift detection
	ScaffoldMode bool      `json:"scaffolded"`   // Whether file was created in scaffold mode (won't overwrite)
	GeneratedAt  time.Time `json:"generated_at"` // When this file entry was created/updated
}

FileEntry represents a single generated file and its metadata. Used to track what generated the file, what caused it to be generated, and whether its content has changed since generation.

type Manifest

type Manifest struct {
	Version     string               `json:"version"` // Webkit CLI version
	GeneratedAt time.Time            `json:"generated_at"`
	Files       map[string]FileEntry `json:"files"` // Filepath to Entry
}

Manifest tracks all files generated by WebKit, including their source and content hashes for drift detection.

func Load

func Load(fs afero.Fs) (*Manifest, error)

Load reads a manifest JSON file and deserializes it. Returns an error if the file doesn't exist or contains invalid JSON.

type Tracker

type Tracker struct {
	// contains filtered or unexported fields
}

Tracker maintains a collection of generated files and their metadata. Used to track which files were created by webkit and from which source.

func NewTracker

func NewTracker() *Tracker

NewTracker creates a tracker with an initialized file map. If a previous manifest is provided, it will be used to preserve timestamps for files that haven't changed.

func (*Tracker) Add

func (t *Tracker) Add(entry FileEntry)

Add stores a file entry in the tracker, keyed by its path. If an entry with the same path exists, it will be overwritten. If the previous manifest contains the same file with the same hash, the GeneratedAt timestamp will be preserved.

func (*Tracker) Save

func (t *Tracker) Save(fs afero.Fs) error

Save writes the tracker's files to a manifest JSON file. Creates parent directories if they don't exist. If a previous manifest was provided and no files have changed, the manifest's GeneratedAt timestamp will be preserved.

func (*Tracker) WithPreviousManifest added in v0.0.5

func (t *Tracker) WithPreviousManifest(previous *Manifest) *Tracker

WithPreviousManifest sets the previous manifest for timestamp preservation.

Jump to

Keyboard shortcuts

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