version

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package version provides utilities for semantic versioning

Index

Constants

View Source
const FrameworkVersion = "0.1.0"

FrameworkVersion is the current version of the framework

Variables

This section is empty.

Functions

func ComputeHash

func ComputeHash(content []byte) string

ComputeHash computes a hash for the given content

func GetFileExtension

func GetFileExtension(path string) string

GetFileExtension gets the extension of a file

func IsBinaryFile

func IsBinaryFile(path string) bool

IsBinaryFile checks if a file is a binary file based on its extension

func IsCodeFile

func IsCodeFile(path string) bool

IsCodeFile checks if a file is a code file based on its extension

func IsConfigFile

func IsConfigFile(path string) bool

IsConfigFile checks if a file is a configuration file based on its extension

func IsPluginVersionCompatible

func IsPluginVersionCompatible(pluginVersion, minFrameworkVersion, maxFrameworkVersion string) (bool, error)

IsPluginVersionCompatible checks if a plugin version is compatible with the framework

func IsTextFile

func IsTextFile(path string) bool

IsTextFile checks if a file is a text file based on its extension

func ReadFileContent

func ReadFileContent(reader io.Reader, maxSize int64) ([]byte, error)

ReadFileContent reads content from a reader up to maxSize bytes

Types

type AnalysisResult

type AnalysisResult struct {
	// LocalVersion is the local version
	LocalVersion *VersionInfo

	// RemoteVersion is the remote version
	RemoteVersion *VersionInfo

	// Diff is the difference between local and remote versions
	Diff *DiffResult

	// DependencyGraph is the dependency graph
	DependencyGraph *DependencyGraph

	// UpdateRequired indicates if an update is required
	UpdateRequired bool

	// ImpactedItems are the items impacted by the update
	ImpactedItems []string

	// AnalysisTime is the time the analysis was performed
	AnalysisTime time.Time
}

AnalysisResult represents the result of a version analysis

type Analyzer

type Analyzer struct {
	// Options are the analyzer options
	Options *AnalyzerOptions

	// LocalRepo is the local repository
	LocalRepo interfaces.Repository

	// RemoteRepo is the remote repository
	RemoteRepo interfaces.Repository

	// DependencyGraph is the dependency graph
	DependencyGraph *DependencyGraph
}

Analyzer analyzes template and module versions

func NewAnalyzer

func NewAnalyzer(localRepo, remoteRepo interfaces.Repository, options *AnalyzerOptions) *Analyzer

NewAnalyzer creates a new version analyzer

func (*Analyzer) AnalyzeAll

func (a *Analyzer) AnalyzeAll(ctx context.Context) (map[string]*AnalysisResult, error)

AnalyzeAll analyzes all templates and modules

func (*Analyzer) AnalyzeModule

func (a *Analyzer) AnalyzeModule(ctx context.Context, modulePath string) (*AnalysisResult, error)

AnalyzeModule analyzes a module

func (*Analyzer) AnalyzeTemplate

func (a *Analyzer) AnalyzeTemplate(ctx context.Context, templatePath string) (*AnalysisResult, error)

AnalyzeTemplate analyzes a template

type AnalyzerOptions

type AnalyzerOptions struct {
	// DiffOptions are the options for file diffing
	DiffOptions *DiffOptions

	// IncludeDependencies determines if dependencies should be analyzed
	IncludeDependencies bool

	// MaxConcurrentOperations is the maximum number of concurrent operations
	MaxConcurrentOperations int

	// Timeout is the timeout for operations
	Timeout time.Duration

	// TemplatePatterns are the patterns for template files
	TemplatePatterns []string

	// ModulePatterns are the patterns for module files
	ModulePatterns []string
}

AnalyzerOptions represents options for the version analyzer

func DefaultAnalyzerOptions

func DefaultAnalyzerOptions() *AnalyzerOptions

DefaultAnalyzerOptions returns the default analyzer options

type Dependency

type Dependency struct {
	// ID is the unique identifier for the dependency
	ID string

	// Type is the type of dependency
	Type DependencyType

	// MinVersion is the minimum required version
	MinVersion *SemVersion

	// MaxVersion is the maximum allowed version
	MaxVersion *SemVersion

	// Optional indicates if the dependency is optional
	Optional bool

	// Path is the path to the dependency
	Path string
}

Dependency represents a dependency on another template, module, or plugin

func NewDependency

func NewDependency(id string, depType DependencyType, minVersion string, optional bool) (*Dependency, error)

NewDependency creates a new dependency

func (*Dependency) IsCompatible

func (d *Dependency) IsCompatible(version *SemVersion) bool

IsCompatible checks if a version is compatible with the dependency

func (*Dependency) WithMaxVersion

func (d *Dependency) WithMaxVersion(maxVersion string) (*Dependency, error)

WithMaxVersion sets the maximum version for the dependency

func (*Dependency) WithPath

func (d *Dependency) WithPath(path string) *Dependency

WithPath sets the path for the dependency

type DependencyGraph

type DependencyGraph struct {
	// Dependencies is a map of dependencies by ID
	Dependencies map[string]*Dependency

	// DependencyTree is a map of dependencies by parent ID
	DependencyTree map[string][]string

	// ReverseDependencies is a map of reverse dependencies by ID
	ReverseDependencies map[string][]string
	// contains filtered or unexported fields
}

DependencyGraph represents a graph of dependencies

func NewDependencyGraph

func NewDependencyGraph() *DependencyGraph

NewDependencyGraph creates a new dependency graph

func (*DependencyGraph) AddDependency

func (g *DependencyGraph) AddDependency(parentID string, dependency *Dependency)

AddDependency adds a dependency to the graph

func (*DependencyGraph) GetAllDependencies

func (g *DependencyGraph) GetAllDependencies(id string) []*Dependency

GetAllDependencies gets all dependencies recursively

func (*DependencyGraph) GetDependencies

func (g *DependencyGraph) GetDependencies(parentID string) []*Dependency

GetDependencies gets all dependencies for a parent ID

func (*DependencyGraph) GetDependency

func (g *DependencyGraph) GetDependency(id string) (*Dependency, bool)

GetDependency gets a dependency by ID

func (*DependencyGraph) GetImpactedDependencies

func (g *DependencyGraph) GetImpactedDependencies(id string) []*Dependency

GetImpactedDependencies gets all dependencies impacted by a change to the given ID

func (*DependencyGraph) GetReverseDependencies

func (g *DependencyGraph) GetReverseDependencies(id string) []*Dependency

GetReverseDependencies gets all reverse dependencies for an ID

func (*DependencyGraph) HasCircularDependency

func (g *DependencyGraph) HasCircularDependency() (bool, string)

HasCircularDependency checks if there is a circular dependency

type DependencyType

type DependencyType string

DependencyType represents the type of dependency

const (
	// TemplateDependency represents a template dependency
	TemplateDependency DependencyType = "template"

	// ModuleDependency represents a module dependency
	ModuleDependency DependencyType = "module"

	// PluginDependency represents a plugin dependency
	PluginDependency DependencyType = "plugin"

	// LibraryDependency represents a library dependency
	LibraryDependency DependencyType = "library"
)

type Diff

type Diff struct {
	OldFiles   []*FileInfo
	NewFiles   []*FileInfo
	OldVersion *SemVersion
	NewVersion *SemVersion
}

Diff represents the differences between two sets of files

type DiffItem

type DiffItem struct {
	// Type is the type of difference
	Type DiffType

	// Path is the path to the item
	Path string

	// OldContent is the old content
	OldContent string

	// NewContent is the new content
	NewContent string

	// LineNumber is the line number of the difference
	LineNumber int

	// LineCount is the number of lines affected
	LineCount int

	// Metadata is additional metadata for the difference
	Metadata map[string]interface{}
}

DiffItem represents a difference item

func NewDiffItem

func NewDiffItem(diffType DiffType, path string, oldContent, newContent string, lineNumber, lineCount int) *DiffItem

NewDiffItem creates a new diff item

func (*DiffItem) String

func (d *DiffItem) String() string

String returns a string representation of the diff item

func (*DiffItem) WithMetadata

func (d *DiffItem) WithMetadata(key string, value interface{}) *DiffItem

WithMetadata adds metadata to the diff item

type DiffOptions

type DiffOptions struct {
	// IgnoreWhitespace determines if whitespace should be ignored
	IgnoreWhitespace bool

	// IgnoreCase determines if case should be ignored
	IgnoreCase bool

	// IgnoreComments determines if comments should be ignored
	IgnoreComments bool

	// IgnoreFormatting determines if formatting should be ignored
	IgnoreFormatting bool

	// IncludeUnchanged determines if unchanged items should be included
	IncludeUnchanged bool

	// MaxContentSize is the maximum content size to read (in bytes)
	MaxContentSize int64
}

DiffOptions represents options for diffing

func DefaultDiffOptions

func DefaultDiffOptions() *DiffOptions

DefaultDiffOptions returns the default diff options

type DiffResult

type DiffResult struct {
	// LocalVersion is the local version
	LocalVersion *VersionInfo

	// RemoteVersion is the remote version
	RemoteVersion *VersionInfo

	// Items is the list of diff items
	Items []*DiffItem

	// Summary is a summary of the differences
	Summary *DiffSummary

	// DiffTime is the time the diff was performed
	DiffTime time.Time
}

DiffResult represents the result of a diff operation

func DiffFiles

func DiffFiles(oldFiles, newFiles []*FileInfo, options *DiffOptions) *DiffResult

DiffFiles creates a diff between two sets of files

func NewDiffResult

func NewDiffResult(localVersion, remoteVersion *VersionInfo) *DiffResult

NewDiffResult creates a new diff result

func (*DiffResult) AddItem

func (r *DiffResult) AddItem(item *DiffItem)

AddItem adds a diff item to the result

func (*DiffResult) GetAddedItems

func (r *DiffResult) GetAddedItems() []*DiffItem

GetAddedItems returns all added items

func (*DiffResult) GetModifiedItems

func (r *DiffResult) GetModifiedItems() []*DiffItem

GetModifiedItems returns all modified items

func (*DiffResult) GetRemovedItems

func (r *DiffResult) GetRemovedItems() []*DiffItem

GetRemovedItems returns all removed items

func (*DiffResult) GetUnchangedItems

func (r *DiffResult) GetUnchangedItems() []*DiffItem

GetUnchangedItems returns all unchanged items

func (*DiffResult) HasDifferences

func (r *DiffResult) HasDifferences() bool

HasDifferences returns true if there are differences

type DiffSummary

type DiffSummary struct {
	// Added is the number of added items
	Added int

	// Removed is the number of removed items
	Removed int

	// Modified is the number of modified items
	Modified int

	// Unchanged is the number of unchanged items
	Unchanged int

	// Total is the total number of items
	Total int
}

DiffSummary represents a summary of differences

func NewDiffSummary

func NewDiffSummary() *DiffSummary

NewDiffSummary creates a new diff summary

func (*DiffSummary) String

func (s *DiffSummary) String() string

String returns a string representation of the diff summary

type DiffType

type DiffType string

DiffType represents the type of difference

const (
	// AddedDiff represents an added item
	AddedDiff DiffType = "added"

	// RemovedDiff represents a removed item
	RemovedDiff DiffType = "removed"

	// ModifiedDiff represents a modified item
	ModifiedDiff DiffType = "modified"

	// UnchangedDiff represents an unchanged item
	UnchangedDiff DiffType = "unchanged"
)

type FileInfo

type FileInfo struct {
	Path    string
	Hash    string
	Size    int64
	ModTime time.Time
	Content []byte
}

FileInfo represents information about a file

type FrameworkInfo

type FrameworkInfo struct {
	// Version is the current version of the framework
	Version string
	// MinPluginVersion is the minimum plugin version supported
	MinPluginVersion string
	// MaxPluginVersion is the maximum plugin version supported
	MaxPluginVersion string
}

FrameworkInfo contains information about the framework

func GetFrameworkInfo

func GetFrameworkInfo() *FrameworkInfo

GetFrameworkInfo returns information about the framework

type SemVersion

type SemVersion struct {
	// Major version number
	Major int

	// Minor version number
	Minor int

	// Patch version number
	Patch int

	// Prerelease identifiers (e.g., "alpha.1", "beta.2")
	Prerelease string

	// Build metadata (e.g., "build.123")
	Build string
}

SemVersion represents a semantic version

func MustParse

func MustParse(version string) *SemVersion

MustParse parses a version string into a SemVersion object It panics if the version string is invalid

func Parse

func Parse(version string) (*SemVersion, error)

Parse parses a version string into a SemVersion object

func (*SemVersion) Compare

func (v *SemVersion) Compare(other *SemVersion) int

Compare compares two versions Returns -1 if v < other, 0 if v == other, 1 if v > other

func (*SemVersion) Equal

func (v *SemVersion) Equal(other *SemVersion) bool

Equal returns true if v == other

func (*SemVersion) GetChangeType

func (v *SemVersion) GetChangeType(other *SemVersion) VersionChangeType

GetChangeType determines the type of change between two versions

func (*SemVersion) GreaterThan

func (v *SemVersion) GreaterThan(other *SemVersion) bool

GreaterThan returns true if v > other

func (*SemVersion) IncrementMajor

func (v *SemVersion) IncrementMajor() *SemVersion

IncrementMajor increments the major version and resets minor and patch to 0

func (*SemVersion) IncrementMinor

func (v *SemVersion) IncrementMinor() *SemVersion

IncrementMinor increments the minor version and resets patch to 0

func (*SemVersion) IncrementPatch

func (v *SemVersion) IncrementPatch() *SemVersion

IncrementPatch increments the patch version

func (*SemVersion) IsBackwardsCompatible

func (v *SemVersion) IsBackwardsCompatible(other *SemVersion) bool

IsBackwardsCompatible checks if the version is backwards compatible with the given version using semantic versioning rules (major version must match and be >= the other version)

func (*SemVersion) IsCompatible

func (v *SemVersion) IsCompatible(other *SemVersion) bool

IsCompatible checks if the version is compatible with the given version using semantic versioning rules (major version must match)

func (*SemVersion) LessThan

func (v *SemVersion) LessThan(other *SemVersion) bool

LessThan returns true if v < other

func (*SemVersion) String

func (v *SemVersion) String() string

String returns the string representation of a version

func (*SemVersion) WithBuild

func (v *SemVersion) WithBuild(build string) *SemVersion

WithBuild returns a new version with the given build string

func (*SemVersion) WithPrerelease

func (v *SemVersion) WithPrerelease(prerelease string) *SemVersion

WithPrerelease returns a new version with the given prerelease string

type Version

type Version = SemVersion

Version is an alias for SemVersion for compatibility

func ParseVersion

func ParseVersion(versionStr string) (Version, error)

ParseVersion parses a version string into a Version struct

type VersionChangeType

type VersionChangeType string

VersionChangeType represents the type of version change

const (
	MajorChange      VersionChangeType = "major"
	MinorChange      VersionChangeType = "minor"
	PatchChange      VersionChangeType = "patch"
	PreReleaseChange VersionChangeType = "prerelease"
	BuildChange      VersionChangeType = "build"
	NoChange         VersionChangeType = "none"
)

type VersionInfo

type VersionInfo struct {
	// ID is the unique identifier for the template or module
	ID string

	// Version is the semantic version
	Version *SemVersion

	// CreatedAt is the creation timestamp
	CreatedAt time.Time

	// UpdatedAt is the last update timestamp
	UpdatedAt time.Time

	// Author is the author of the template or module
	Author string

	// Description is a description of the template or module
	Description string

	// Tags are tags associated with the template or module
	Tags []string

	// Metadata is additional metadata for the template or module
	Metadata map[string]interface{}
}

VersionInfo represents version information for a template or module

func NewVersionInfo

func NewVersionInfo(id string, version string, author string, description string) (*VersionInfo, error)

NewVersionInfo creates a new version info object

func (*VersionInfo) GetVersionString

func (v *VersionInfo) GetVersionString() string

GetVersionString returns the string representation of the version

func (*VersionInfo) IncrementMajor

func (v *VersionInfo) IncrementMajor()

IncrementMajor increments the major version

func (*VersionInfo) IncrementMinor

func (v *VersionInfo) IncrementMinor()

IncrementMinor increments the minor version

func (*VersionInfo) IncrementPatch

func (v *VersionInfo) IncrementPatch()

IncrementPatch increments the patch version

func (*VersionInfo) IsBackwardsCompatible

func (v *VersionInfo) IsBackwardsCompatible(other *VersionInfo) bool

IsBackwardsCompatible checks if the version info is backwards compatible with another version info

func (*VersionInfo) IsCompatible

func (v *VersionInfo) IsCompatible(other *VersionInfo) bool

IsCompatible checks if the version info is compatible with another version info

func (*VersionInfo) UpdateVersion

func (v *VersionInfo) UpdateVersion(version string) error

UpdateVersion updates the version and sets the updated timestamp

func (*VersionInfo) WithMetadata

func (v *VersionInfo) WithMetadata(key string, value interface{}) *VersionInfo

WithMetadata adds metadata to the version info

func (*VersionInfo) WithTag

func (v *VersionInfo) WithTag(tag string) *VersionInfo

WithTag adds a tag to the version info

Directories

Path Synopsis
Package version provides utilities for semantic versioning
Package version provides utilities for semantic versioning
Package version provides utilities for semantic versioning
Package version provides utilities for semantic versioning

Jump to

Keyboard shortcuts

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