Documentation
¶
Overview ¶
GoPackage generator provides functionality for processing templating actions, including adding single files or multiple files to a destination directory.
Index ¶
- Constants
- Variables
- func GenerateActionFile(entityType string, data *TemplateData, actions []Action, ...) error
- func GenerateActionJSONFile(filePath string, actions ActionList) error
- func ProcessActions(logger logger.LoggerInterface, actions []Action, data *TemplateData) error
- func ProcessEntityActions(logger logger.LoggerInterface, pathToActionsFile string, data *TemplateData, ...) error
- type Action
- type ActionHandler
- type ActionList
- type CopyAction
- type JSONAction
- type JSONActionList
- type RenderAction
- type TemplateData
Constants ¶
const ( RenderActionId = "render" CopyActionId = "copy" )
Variables ¶
var LoadUserActionsFunc = LoadUserActions
LoadUserActionsFunc is a function variable to allow testing overrides.
var ProcessActionsFunc = ProcessActions
Default function implementation
Functions ¶
func GenerateActionFile ¶
func GenerateActionFile(entityType string, data *TemplateData, actions []Action, logger logger.LoggerInterface) error
GenerateActionFile generates an action file for the given entity type.
func GenerateActionJSONFile ¶
func GenerateActionJSONFile(filePath string, actions ActionList) error
GenerateActionJSONFile marshals a slice of Actions into a JSON file.
func ProcessActions ¶
func ProcessActions(logger logger.LoggerInterface, actions []Action, data *TemplateData) error
ProcessActions processes a list of actions using the appropriate handlers.
func ProcessEntityActions ¶
func ProcessEntityActions(logger logger.LoggerInterface, pathToActionsFile string, data *TemplateData, cfg *config.Config) error
ProcessEntityActions retrieves and processes actions from a JSON file.
Types ¶
type Action ¶
type Action struct {
Type string `json:"type,omitempty"` // "copy" or "render"
Item string `json:"item,omitempty"` // "file" or "folder"
Path string `json:"path,omitempty"` // Output path (for "file")
TemplateFile string `json:"templateFile,omitempty"` // Template file path (for "file")
Source string `json:"source,omitempty"` // Base directory (for "folder")
Destination string `json:"destination,omitempty"` // Destination directory (for "folder")
OnlyIfJs bool `json:"onlyIfJs,omitempty"` // Include only if --js is true
SkipIfExists bool `json:"skipIfExists,omitempty"` // Skips a file if it already exists
Force bool `json:"force,omitempty"` // Overwrites files if they exist
}
Action represents a templating action with configurable properties. It is used internally to process actions based on type (copy/render).
func BuildComponentActions ¶
BuildComponentActions generates the list of actions required to scaffold a new component.
func BuildVariantActions ¶
BuildVariantActions generates the list of actions required to scaffold a new variant for an existing component.
func (*Action) ToJSONAction ¶
func (a *Action) ToJSONAction() JSONAction
ToJSONAction converts an Action to JSONAction.
type ActionHandler ¶
type ActionHandler interface {
Execute(action Action, data *TemplateData) error
}
ActionHandler defines the interface for processing actions.
type ActionList ¶
type ActionList []Action
ActionList represents a collection of Action objects.
func (ActionList) ToJSONAction ¶
func (al ActionList) ToJSONAction() []JSONAction
ToJSONAction converts an ActionList to a slice of JSONAction.
type CopyAction ¶
type CopyAction struct{}
CopyAction handles copying files and folders.
func (*CopyAction) Execute ¶
func (a *CopyAction) Execute(action Action, data *TemplateData) error
type JSONAction ¶
type JSONAction struct {
Item string `json:"item"`
TemplateFile string `json:"templateFile,omitempty"`
Path string `json:"path,omitempty"`
Source string `json:"source,omitempty"`
Destination string `json:"destination,omitempty"`
OnlyIfJs bool `json:"onlyIfJs,omitempty"` // Include only if --js is true
SkipIfExists bool `json:"skipIfExists,omitempty"` // Skips a file if it already exists
Force bool `json:"force,omitempty"` // Overwrites files if they exist
}
JSONAction represents a templating action without the `Type` field.
func LoadUserActions ¶
func LoadUserActions(filePath string) ([]JSONAction, error)
LoadUserActions reads an actions.json file and parses it into a slice of JSONAction structs.
func (*JSONAction) ToAction ¶
func (jsa *JSONAction) ToAction(actionType string) Action
ToAction converts a JSONAction to an Action with a specified type.
type JSONActionList ¶
type JSONActionList []JSONAction
JSONActionList represents a collection of JSONAction objects.
func RetrieveActionsFile ¶
func RetrieveActionsFile(logger logger.LoggerInterface, actionFilePath string, cfg *config.Config) (JSONActionList, error)
RetrieveActionsFile retrieves actions from a JSON file.
func (JSONActionList) ToActions ¶
func (jsaList JSONActionList) ToActions(actionType string) []Action
ToActions converts a JSONActionList to a slice of Action with a specified type.
type RenderAction ¶
type RenderAction struct{}
RenderAction handles rendering templates into files or folders.
func (*RenderAction) Execute ¶
func (a *RenderAction) Execute(action Action, data *TemplateData) error
type TemplateData ¶
type TemplateData struct {
TemplatesDir string
ActionsDir string
GoModule string
GoPackage string
ComponentName string
VariantName string
AssetsDir string
WithJs bool
CssLayer string
GuardMarker string
Force bool
DryRun bool
UserData map[string]any
}
TemplateData represents the data used to populate templates during file generation.
Fields: - TemplatesDir: The root directory containing template files. - ActionsDir: The root directory containing actions files. - GoModule: The name of the Go module being worked on. - GoPackage: The Go package name where components will be organized and generated. - ComponentName: The name of the component being generated. - VariantName: The name of the variant being generated (if applicable). - AssetsDir: The directory where asset files (e.g., CSS, JS) will be generated. - WithJs: Indicates whether or not JavaScript is required for the component. - CssLayer: The name of the CSS layer to associate with component styles. - GuardMarker: A text placeholder or sentinel used in template files to mark auto-generated sections. - Force: If true, existing files will be overwritten without prompting for confirmation. - DryRun: If true, no files will be written; instead, the process will simulate changes and display what would happen.