feature

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddDependencies

func AddDependencies(projectRoot string, deps []Dependency) error

AddDependencies adds Go module dependencies to go.mod.

func AddInstalledFeature

func AddInstalledFeature(projectRoot, name, version string) error

AddInstalledFeature adds a feature to the installed list.

func FeaturesPath

func FeaturesPath(projectRoot string) string

FeaturesPath returns the path to the features tracking file.

func FileExists

func FileExists(path string) bool

FileExists checks if a file exists.

func MkdirAll

func MkdirAll(path string, perm os.FileMode) error

MkdirAll creates directories.

func ReadFile

func ReadFile(path string) ([]byte, error)

ReadFile reads a file content.

func RemoveEnvironment

func RemoveEnvironment(projectRoot string, envVars []string) error

RemoveEnvironment removes environment variables from .env.example.

func RemoveInstalledFeature

func RemoveInstalledFeature(projectRoot, name string) error

RemoveInstalledFeature removes a feature from the installed list.

func RunGoFmt

func RunGoFmt(projectRoot string) error

RunGoFmt runs gofmt on all Go files in the project.

func RunGoModTidy

func RunGoModTidy(projectRoot string) error

RunGoModTidy runs go mod tidy in the project directory.

func SaveFeatures

func SaveFeatures(projectRoot string, f FeaturesFile) error

SaveFeatures saves the installed features to .forge/features.yaml.

func UpdateEnvironment

func UpdateEnvironment(projectRoot string, envVars []string) error

UpdateEnvironment appends environment variables to .env.example.

func WriteFile

func WriteFile(path string, content []byte) error

WriteFile writes content to a file.

Types

type Conflict

type Conflict struct {
	File        string
	Description string
}

Conflict describes a potential conflict during feature installation.

type Dependency

type Dependency struct {
	Module  string
	Version string
}

Dependency represents a Go module dependency.

type Detector

type Detector struct{}

Detector detects and loads information about a ForgeKit project.

func (Detector) Detect

func (Detector) Detect(root string) (ProjectContext, error)

Detect inspects the project root and returns its context. Strict mode: requires ForgeKit project structure (.forge or legacy features.yaml).

func (Detector) DetectLoose

func (Detector) DetectLoose(root string) (ProjectContext, error)

DetectLoose inspects the project root and returns its context. Loose mode: accepts ForgeKit projects, legacy projects, and external compatible Go projects.

type Feature

type Feature interface {
	Name() string
	Description() string
	Version() string

	Check(ctx context.Context, project ProjectContext) error
	Plan(ctx context.Context, project ProjectContext) (Plan, error)
	Apply(ctx context.Context, project ProjectContext, plan Plan) error
}

Feature represents an installable ForgeKit feature.

type FeatureDependencies

type FeatureDependencies interface {
	DependsOn() []string
}

FeatureDependencies is an optional interface for features that declare dependencies on other features.

type FeatureRemover

type FeatureRemover interface {
	Remove(ctx context.Context, project ProjectContext, plan Plan) error
}

FeatureRemover is an optional interface for features that support removal.

type FeaturesFile

type FeaturesFile struct {
	Features []InstalledFeature `yaml:"features"`
}

FeaturesFile represents the .forge/features.yaml file.

func LoadFeatures

func LoadFeatures(projectRoot string) (FeaturesFile, error)

LoadFeatures loads the installed features from .forge/features.yaml.

type FileAction

type FileAction struct {
	Source      string
	Destination string
	Action      FileActionType
}

FileAction describes a file operation performed by a feature.

type FileActionType

type FileActionType string

FileActionType represents the type of file operation.

const (
	FileActionCreate FileActionType = "create"
	FileActionModify FileActionType = "modify"
	FileActionDelete FileActionType = "delete"
)

type FileChange

type FileChange struct {
	Path       string
	Existed    bool
	OldContent []byte
}

FileChange represents a file modification for rollback tracking.

type InstalledFeature

type InstalledFeature struct {
	Name        string    `yaml:"name"`
	Version     string    `yaml:"version"`
	InstalledAt time.Time `yaml:"installed_at"`
}

InstalledFeature represents a feature installed in the project.

func IsInstalled

func IsInstalled(projectRoot, name string) (bool, *InstalledFeature, error)

IsInstalled checks if a feature is already installed.

type Installer

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

Installer applies feature plans with rollback capability.

func NewInstaller

func NewInstaller(projectRoot string, console *output.Console, dryRun bool) *Installer

NewInstaller creates an installer for a project.

func (*Installer) Apply

func (i *Installer) Apply(ctx context.Context, plan Plan) error

Apply executes a feature plan with rollback on failure.

func (*Installer) Changes

func (i *Installer) Changes() []FileChange

Changes returns the list of recorded changes (for inspection).

func (*Installer) Rollback

func (i *Installer) Rollback() error

Rollback restores all modified files to their original state.

type Manifest

type Manifest struct {
	Name         string
	Version      string
	Description  string
	Dependencies []Dependency
	Files        []FileAction
	Environment  []string
}

Manifest describes the resources required by a feature.

type Plan

type Plan struct {
	Feature      string
	Version      string
	Files        []FileAction
	Dependencies []Dependency
	Environment  []string
	Conflicts    []Conflict
}

Plan describes the changes a feature intends to make.

type ProjectContext

type ProjectContext struct {
	Root      string
	Module    string
	GoVersion string
	HTTPPort  int
	Type      ProjectType
}

ProjectContext describes the ForgeKit project receiving a feature.

type ProjectType

type ProjectType int

ProjectType represents the type of project detected.

const (
	ProjectTypeUnknown ProjectType = iota
	ProjectTypeForgeKit
	ProjectTypeLegacyForgeKit
	ProjectTypeExternalCompatible
	ProjectTypeInvalidForgeKit
)

type Registry

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

Registry stores the available ForgeKit features.

func NewRegistry

func NewRegistry(features ...Feature) *Registry

NewRegistry creates a feature registry.

func (*Registry) Get

func (r *Registry) Get(name string) (Feature, bool)

Get returns a feature by name.

func (*Registry) HasCycles

func (r *Registry) HasCycles(names []string) bool

HasCycles checks if there are circular dependencies among the given feature names.

func (*Registry) List

func (r *Registry) List() []Feature

List returns all registered features sorted by name.

func (*Registry) Register

func (r *Registry) Register(f Feature)

Register adds a feature to the registry.

func (*Registry) Require

func (r *Registry) Require(name string) (Feature, error)

Require returns a feature or an explicit error.

func (*Registry) ResolveDependencies

func (r *Registry) ResolveDependencies(names []string) ([]Feature, error)

ResolveDependencies returns features in topological order based on their DependsOn() declarations. Features without FeatureDependencies interface are treated as having no dependencies. Returns an error if a cycle is detected or a dependency is not registered.

type TemplateRenderer

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

TemplateRenderer renders template files.

func NewTemplateRenderer

func NewTemplateRenderer(data map[string]string) *TemplateRenderer

NewTemplateRenderer creates a template renderer.

func (*TemplateRenderer) RenderFile

func (t *TemplateRenderer) RenderFile(sourcePath, destPath string) error

RenderFile reads a template file and replaces placeholders.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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