utils

package
v3.10.0 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ConfigDir      = ".bffgen"
	ConfigFile     = "bffgen.yaml"
	ConfigDirPerm  = 0o700 // User only: read, write, execute
	ConfigFilePerm = 0o600 // User only: read, write
)
View Source
const (
	// File and directory permissions
	BackupDirPerm   = 0o700 // User only: read, write, execute
	BackupFilePerm  = 0o600 // User only: read, write
	ProjectDirPerm  = 0o755 // Standard directory permissions
	ProjectFilePerm = 0o644 // Standard file permissions (source code)

	// Backup retention policy
	BackupRetentionDays = 30
	MaxBackupsToKeep    = 5
)

Variables

This section is empty.

Functions

func CheckRequiredTools

func CheckRequiredTools(projectType string) ([]ToolInfo, []ToolInfo)

CheckRequiredTools checks all required tools for a project type

func CleanupOldBackups

func CleanupOldBackups(olderThan time.Duration) error

CleanupOldBackups removes backups older than specified duration

func ConfigToJSON

func ConfigToJSON(config *types.BFFConfig) ([]byte, error)

ConfigToJSON converts BFF configuration to JSON format

func ConvertJSONToYAML

func ConvertJSONToYAML(outputPath string) error

ConvertJSONToYAML converts bffgen.config.json to bff.config.yaml

func ConvertYAMLToJSON

func ConvertYAMLToJSON(outputPath string) error

ConvertYAMLToJSON converts bff.config.yaml to bffgen.config.json

func GetBackupDir

func GetBackupDir() string

GetBackupDir returns the path to the backup directory

func GetConfigPath

func GetConfigPath() (string, error)

GetConfigPath returns the path to the bffgen configuration file

func GetCurrentTimestamp

func GetCurrentTimestamp() string

GetCurrentTimestamp returns the current timestamp as a string

func GetStateDir

func GetStateDir() string

GetStateDir returns the state directory path

func GetToolInstallInstructions

func GetToolInstallInstructions(toolName string) string

GetToolInstallInstructions returns installation instructions for a tool

func HasRequiredTools

func HasRequiredTools(projectType string) bool

HasRequiredTools checks if all required tools are installed

func LoadBFFGenConfig

func LoadBFFGenConfig() (*types.BFFGenConfig, error)

LoadBFFGenConfig loads the bffgen configuration from file

func LoadConfig

func LoadConfig(configPath string) (*types.BFFConfig, error)

LoadConfig loads BFF configuration from a YAML file

func PrintToolStatus

func PrintToolStatus(required, optional []ToolInfo)

PrintToolStatus prints the status of tools

func SaveBFFGenConfig

func SaveBFFGenConfig(config *types.BFFGenConfig) error

SaveBFFGenConfig saves the bffgen configuration to file with restricted permissions

func SaveConfig

func SaveConfig(config *types.BFFConfig, configPath string) error

SaveConfig saves BFF configuration to a YAML file

func SaveState

func SaveState(state *GenerationState) error

SaveState saves the generation state to .bffgen/state.json

func UpdateRecentProject

func UpdateRecentProject(projectName string) error

UpdateRecentProject adds a project to the recent projects list

func WrapOperation

func WrapOperation(fn func(*FileTransaction) error) error

WrapOperation wraps a function in a transaction and executes it

Types

type ColorizedDiff

type ColorizedDiff struct {
	FilePath     string
	OldContent   string
	NewContent   string
	ContextLines int // Number of context lines to show
}

ColorizedDiff generates a colorized git-style diff

func NewColorizedDiff

func NewColorizedDiff(filePath, oldContent, newContent string) *ColorizedDiff

NewColorizedDiff creates a new colorized diff

func (*ColorizedDiff) Generate

func (cd *ColorizedDiff) Generate() string

Generate generates the colorized diff output

func (*ColorizedDiff) GenerateSummary

func (cd *ColorizedDiff) GenerateSummary() string

GenerateSummary generates a summary of changes

type DiffHunk

type DiffHunk struct {
	OldStart int
	OldCount int
	NewStart int
	NewCount int
	Lines    []DiffLine
}

DiffHunk represents a chunk of related changes

type DiffLine

type DiffLine struct {
	Type    DiffLineType
	LineNum int
	Content string
}

DiffLine represents a single line in a diff

type DiffLineType

type DiffLineType int

DiffLineType represents the type of diff line

const (
	DiffLineContext DiffLineType = iota
	DiffLineAdded
	DiffLineRemoved
	DiffLineModified
)

type FileOperation

type FileOperation struct {
	Type         OperationType
	Path         string
	OriginalData []byte
	NewData      []byte
	Executed     bool
}

FileOperation represents a single file operation

type FileTransaction

type FileTransaction struct {
	*Transaction
}

FileTransaction is a helper for common file transaction patterns

func NewFileTransaction

func NewFileTransaction() *FileTransaction

NewFileTransaction creates a new file transaction

func (*FileTransaction) CreateFile

func (ft *FileTransaction) CreateFile(path string, content []byte) error

CreateFile adds a file creation to the transaction

func (*FileTransaction) DeleteFile

func (ft *FileTransaction) DeleteFile(path string) error

DeleteFile adds a file deletion to the transaction

func (*FileTransaction) ExecuteAndCommit

func (ft *FileTransaction) ExecuteAndCommit() error

ExecuteAndCommit executes the transaction and commits if successful

func (*FileTransaction) UpdateFile

func (ft *FileTransaction) UpdateFile(path string, newContent []byte) error

UpdateFile adds a file update to the transaction

type GeneratedFile

type GeneratedFile struct {
	Path         string    `json:"path"`
	GeneratedAt  time.Time `json:"generatedAt"`
	Hash         string    `json:"hash"` // SHA256 hash of generated content
	HasMarkers   bool      `json:"hasMarkers"`
	UserModified bool      `json:"userModified"`
}

GeneratedFile represents a file that was generated

type GenerationState

type GenerationState struct {
	Version        string                    `json:"version"`
	LastGeneration time.Time                 `json:"lastGeneration"`
	GeneratedFiles map[string]*GeneratedFile `json:"generatedFiles"`
	Routes         map[string]*RouteState    `json:"routes"`
	ProjectType    string                    `json:"projectType"` // "go", "nodejs"
	Framework      string                    `json:"framework"`   // "chi", "express", "fastify", etc.
}

GenerationState tracks the state of generated files

func InitializeState

func InitializeState(projectType, framework string) (*GenerationState, error)

InitializeState initializes a new generation state for a project

func LoadState

func LoadState() (*GenerationState, error)

LoadState loads the generation state from .bffgen/state.json

func (*GenerationState) IsFileGenerated

func (s *GenerationState) IsFileGenerated(path string) bool

IsFileGenerated checks if a file has been generated before

func (*GenerationState) IsRouteGenerated

func (s *GenerationState) IsRouteGenerated(service, method, exposeAs string) bool

IsRouteGenerated checks if a route has already been generated

func (*GenerationState) TrackGeneratedFile

func (s *GenerationState) TrackGeneratedFile(path, contentHash string, hasMarkers bool)

TrackGeneratedFile adds or updates a generated file in the state

func (*GenerationState) TrackRoute

func (s *GenerationState) TrackRoute(service, method, path, exposeAs string)

TrackRoute adds or updates a route in the state

type MultiFileDiff

type MultiFileDiff struct {
	Files map[string]*ColorizedDiff
}

MultiFileDiff handles diffs for multiple files

func NewMultiFileDiff

func NewMultiFileDiff() *MultiFileDiff

NewMultiFileDiff creates a new multi-file diff

func (*MultiFileDiff) AddFile

func (mfd *MultiFileDiff) AddFile(path, oldContent, newContent string)

AddFile adds a file to the diff

func (*MultiFileDiff) Generate

func (mfd *MultiFileDiff) Generate() string

Generate generates the full multi-file diff

func (*MultiFileDiff) GenerateSummary

func (mfd *MultiFileDiff) GenerateSummary() string

GenerateSummary generates a summary for all files

type OperationType

type OperationType int

OperationType represents the type of file operation

const (
	OpCreate OperationType = iota
	OpUpdate
	OpDelete
)

type ProgressTracker

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

ProgressTracker tracks progress of multi-step operations

func NewProgressTracker

func NewProgressTracker(description string, totalSteps int) *ProgressTracker

NewProgressTracker creates a new progress tracker

func (*ProgressTracker) Fail

func (pt *ProgressTracker) Fail(message string)

Fail marks the progress as failed

func (*ProgressTracker) Finish

func (pt *ProgressTracker) Finish()

Finish completes the progress bar

func (*ProgressTracker) GetElapsed

func (pt *ProgressTracker) GetElapsed() time.Duration

GetElapsed returns the elapsed time

func (*ProgressTracker) SetStep

func (pt *ProgressTracker) SetStep(step int, message string)

SetStep sets the current step with a message

func (*ProgressTracker) Step

func (pt *ProgressTracker) Step(message string)

Step increments the progress by one step

type PromptConfig

type PromptConfig struct {
	Reader   *bufio.Reader
	Defaults types.Defaults
}

PromptConfig contains configuration for prompts

func NewPromptConfig

func NewPromptConfig(reader *bufio.Reader, defaults types.Defaults) *PromptConfig

NewPromptConfig creates a new prompt configuration

func (*PromptConfig) ConfirmAddMore

func (p *PromptConfig) ConfirmAddMore() bool

ConfirmAddMore prompts user to confirm adding more services

func (*PromptConfig) PromptBackendArchitecture

func (p *PromptConfig) PromptBackendArchitecture() (string, error)

PromptBackendArchitecture prompts user for backend architecture

func (*PromptConfig) PromptCORSSetting

func (p *PromptConfig) PromptCORSSetting() ([]string, error)

PromptCORSSetting prompts user for CORS origins

func (*PromptConfig) PromptHybridURL

func (p *PromptConfig) PromptHybridURL(serviceName string) (string, error)

PromptHybridURL prompts user for hybrid service URL

func (*PromptConfig) PromptLanguageSelection

func (p *PromptConfig) PromptLanguageSelection() (scaffolding.LanguageType, string, error)

PromptLanguageSelection prompts user to select programming language/runtime

func (*PromptConfig) PromptMonolithicURL

func (p *PromptConfig) PromptMonolithicURL() (string, error)

PromptMonolithicURL prompts user for monolithic backend URL

func (*PromptConfig) PromptRouteConfiguration

func (p *PromptConfig) PromptRouteConfiguration() (string, error)

PromptRouteConfiguration prompts user for route configuration

func (*PromptConfig) PromptServiceURL

func (p *PromptConfig) PromptServiceURL(serviceName string, defaultURL string) (string, error)

PromptServiceURL prompts user for service URL

func (*PromptConfig) PromptServicename

func (p *PromptConfig) PromptServicename(serviceNum int) (string, error)

PromptServicename prompts user for service name

type QuietProgress

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

QuietProgress provides minimal progress output (just icons)

func NewQuietProgress

func NewQuietProgress(verbose bool) *QuietProgress

NewQuietProgress creates a quiet progress tracker

func (*QuietProgress) Error

func (qp *QuietProgress) Error(message string)

Error indicates an error

func (*QuietProgress) Info

func (qp *QuietProgress) Info(message string)

Info provides information

func (*QuietProgress) Start

func (qp *QuietProgress) Start(message string)

Start indicates an operation is starting

func (*QuietProgress) Success

func (qp *QuietProgress) Success(message string)

Success indicates successful completion

func (*QuietProgress) Warning

func (qp *QuietProgress) Warning(message string)

Warning indicates a warning

type RouteState

type RouteState struct {
	Service   string    `json:"service"`
	Method    string    `json:"method"`
	Path      string    `json:"path"`
	ExposeAs  string    `json:"exposeAs"`
	Generated time.Time `json:"generated"`
}

RouteState represents the state of a route

type Spinner

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

Spinner provides a simple spinner for indeterminate operations

func NewSpinner

func NewSpinner(message string) *Spinner

NewSpinner creates a new spinner

func (*Spinner) Start

func (s *Spinner) Start()

Start starts the spinner

func (*Spinner) Stop

func (s *Spinner) Stop()

Stop stops the spinner

func (*Spinner) UpdateMessage

func (s *Spinner) UpdateMessage(message string)

UpdateMessage updates the spinner message

type StepProgress

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

StepProgress represents a simple step-based progress indicator

func NewStepProgress

func NewStepProgress(totalSteps int) *StepProgress

NewStepProgress creates a new step progress tracker

func (*StepProgress) Fail

func (sp *StepProgress) Fail(message string)

Fail marks a failure

func (*StepProgress) Finish

func (sp *StepProgress) Finish(message string)

Finish completes the progress

func (*StepProgress) Step

func (sp *StepProgress) Step(message string)

Step advances to the next step with a message

type ToolInfo

type ToolInfo struct {
	Name      string
	Command   string
	Installed bool
	Version   string
	Required  bool
}

ToolInfo represents information about an installed tool

func CheckTool

func CheckTool(name, command string) *ToolInfo

CheckTool checks if a tool is installed and gets its version

type Transaction

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

Transaction represents a set of file operations that can be rolled back

func NewTransaction

func NewTransaction() *Transaction

NewTransaction creates a new file transaction

func (*Transaction) AddCreate

func (t *Transaction) AddCreate(path string, data []byte)

AddCreate adds a file creation operation

func (*Transaction) AddDelete

func (t *Transaction) AddDelete(path string, data []byte)

AddDelete adds a file deletion operation

func (*Transaction) AddUpdate

func (t *Transaction) AddUpdate(path string, oldData, newData []byte)

AddUpdate adds a file update operation

func (*Transaction) Commit

func (t *Transaction) Commit() error

Commit marks the transaction as successfully completed and cleans up backups

func (*Transaction) Execute

func (t *Transaction) Execute() error

Execute executes all operations in the transaction

func (*Transaction) GetBackupDir

func (t *Transaction) GetBackupDir() string

GetBackupDir returns the backup directory path

func (*Transaction) GetOperationCount

func (t *Transaction) GetOperationCount() int

GetOperationCount returns the number of operations in the transaction

func (*Transaction) IsCompleted

func (t *Transaction) IsCompleted() bool

IsCompleted returns whether the transaction has been completed

func (*Transaction) Rollback

func (t *Transaction) Rollback() error

Rollback manually rolls back all operations

Jump to

Keyboard shortcuts

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