customization

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package customization provides functionality for identifying, preserving, and reapplying user customizations during template and module updates.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CustomizationEntry

type CustomizationEntry struct {
	// ID is the unique identifier for the customization
	ID string `json:"id"`
	// Type is the type of customization
	Type CustomizationType `json:"type"`
	// Path is the path to the customized file, relative to the component root
	Path string `json:"path"`
	// ComponentID is the ID of the template or module
	ComponentID string `json:"component_id"`
	// BaseVersion is the version of the component that was customized
	BaseVersion string `json:"base_version"`
	// CustomizationDate is the date the customization was made
	CustomizationDate time.Time `json:"customization_date"`
	// Hash is the hash of the original file content
	OriginalHash string `json:"original_hash"`
	// CustomizedHash is the hash of the customized file content
	CustomizedHash string `json:"customized_hash"`
	// Markers contains the customization markers found in the file
	Markers []CustomizationMarker `json:"markers,omitempty"`
	// Policy is the preservation policy for this customization
	Policy PreservationPolicy `json:"policy"`
}

CustomizationEntry represents a single customization entry in the registry

type CustomizationMarker

type CustomizationMarker struct {
	// Type is the type of marker
	Type string `json:"type"`
	// StartLine is the line number where the marker starts
	StartLine int `json:"start_line"`
	// EndLine is the line number where the marker ends
	EndLine int `json:"end_line"`
	// Content is the content of the marker
	Content string `json:"content,omitempty"`
}

CustomizationMarker represents a marker for customization in a file

type CustomizationType

type CustomizationType string

CustomizationType represents the type of customization

const (
	// TemplateCustomization represents a customization to a template
	TemplateCustomization CustomizationType = "template"
	// ModuleCustomization represents a customization to a module
	ModuleCustomization CustomizationType = "module"
)

type Detector

type Detector struct {
	// Registry is the customization registry
	Registry *Registry
	// BaseDir is the directory containing the original templates and modules
	BaseDir string
	// CustomizedDir is the directory containing the customized templates and modules
	CustomizedDir string
}

Detector identifies user customizations in templates and modules

func NewDetector

func NewDetector(options *DetectorOptions) (*Detector, error)

NewDetector creates a new customization detector

func (*Detector) DetectModuleCustomizations

func (d *Detector) DetectModuleCustomizations() ([]*CustomizationEntry, error)

DetectModuleCustomizations detects customizations in modules

func (*Detector) DetectTemplateCustomizations

func (d *Detector) DetectTemplateCustomizations() ([]*CustomizationEntry, error)

DetectTemplateCustomizations detects customizations in templates

func (*Detector) RegisterCustomizations

func (d *Detector) RegisterCustomizations() error

RegisterCustomizations registers all detected customizations in the registry

type DetectorOptions

type DetectorOptions struct {
	// Registry is the customization registry
	Registry *Registry
	// BaseDir is the directory containing the original templates and modules
	BaseDir string
	// CustomizedDir is the directory containing the customized templates and modules
	CustomizedDir string
}

DetectorOptions contains options for the Detector

type PreservationPolicy

type PreservationPolicy string

PreservationPolicy represents the policy for preserving customizations

const (
	// AlwaysPreserve means the customization should always be preserved
	AlwaysPreserve PreservationPolicy = "always_preserve"
	// PreserveWithConflictResolution means the customization should be preserved with conflict resolution
	PreserveWithConflictResolution PreservationPolicy = "preserve_with_conflict_resolution"
	// AskUser means the user should be asked what to do with the customization
	AskUser PreservationPolicy = "ask_user"
	// Discard means the customization should be discarded
	Discard PreservationPolicy = "discard"
)

type Preserver

type Preserver struct {
	// Registry is the customization registry
	Registry *Registry
	// InstallDir is the directory where the tool is installed
	InstallDir string
	// BackupDir is the directory for backups during update
	BackupDir string
	// Logger is the logger for preserver operations
	Logger *os.File
}

Preserver preserves and reapplies user customizations during updates

func NewPreserver

func NewPreserver(options *PreserverOptions) (*Preserver, error)

NewPreserver creates a new customization preserver

func (*Preserver) PreserveModuleCustomizations

func (p *Preserver) PreserveModuleCustomizations() error

PreserveModuleCustomizations preserves module customizations before update

func (*Preserver) PreserveTemplateCustomizations

func (p *Preserver) PreserveTemplateCustomizations() error

PreserveTemplateCustomizations preserves template customizations before update

func (*Preserver) ReapplyModuleCustomizations

func (p *Preserver) ReapplyModuleCustomizations(updatedModules []string) error

ReapplyModuleCustomizations reapplies module customizations after update

func (*Preserver) ReapplyTemplateCustomizations

func (p *Preserver) ReapplyTemplateCustomizations(updatedTemplates []string) error

ReapplyTemplateCustomizations reapplies template customizations after update

type PreserverOptions

type PreserverOptions struct {
	// Registry is the customization registry
	Registry *Registry
	// InstallDir is the directory where the tool is installed
	InstallDir string
	// BackupDir is the directory for backups during update
	BackupDir string
	// LogFile is the file to log preserver operations
	LogFile *os.File
}

PreserverOptions contains options for the Preserver

type Registry

type Registry struct {
	// Entries is a map of customization entries by ID
	Entries map[string]*CustomizationEntry `json:"entries"`
	// RegistryPath is the path to the registry file
	RegistryPath string `json:"-"`
}

Registry represents the customization registry

func NewRegistry

func NewRegistry(registryPath string) (*Registry, error)

NewRegistry creates a new customization registry

func (*Registry) AddEntry

func (r *Registry) AddEntry(entry *CustomizationEntry)

AddEntry adds a customization entry to the registry

func (*Registry) GetEntriesByComponentID

func (r *Registry) GetEntriesByComponentID(componentID string, entryType CustomizationType) []*CustomizationEntry

GetEntriesByComponentID gets all customization entries for a component

func (*Registry) GetEntriesByPath

func (r *Registry) GetEntriesByPath(path string, entryType CustomizationType) []*CustomizationEntry

GetEntriesByPath gets all customization entries for a path

func (*Registry) GetEntry

func (r *Registry) GetEntry(id string) *CustomizationEntry

GetEntry gets a customization entry from the registry

func (*Registry) Load

func (r *Registry) Load() error

Load loads the registry from disk

func (*Registry) RemoveEntry

func (r *Registry) RemoveEntry(id string)

RemoveEntry removes a customization entry from the registry

func (*Registry) Save

func (r *Registry) Save() error

Save saves the registry to disk

Jump to

Keyboard shortcuts

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