templates

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2025 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// DefaultGitHubIndex points to the community templates repo index.
	DefaultGitHubIndex = "https://raw.githubusercontent.com/AltairaLabs/promptkit-templates/main/index.yaml"
)
View Source
const (
	// DefaultRepoName is the built-in shorthand for the community template repository.
	DefaultRepoName = "community"
)

Variables

View Source
var DefaultIndex = DefaultGitHubIndex

DefaultIndex is the index location used for remote loads (overridable in tests).

Functions

func DefaultCacheDir added in v1.1.3

func DefaultCacheDir() string

DefaultCacheDir returns the default cache directory, preferring the user cache dir.

func DefaultRepoConfigPath added in v1.1.3

func DefaultRepoConfigPath() string

DefaultRepoConfigPath returns the default config file location for template repos.

func FetchTemplate added in v1.1.3

func FetchTemplate(entry *IndexEntry, cacheDir string) (string, error)

FetchTemplate copies the template source into cacheDir/<name>/<version>/template.yaml.

func RenderDryRun added in v1.1.3

func RenderDryRun(pkg *TemplatePackage, vars map[string]string, outDir string) error

RenderDryRun renders the package with vars and writes to outDir.

func ResolveIndex added in v1.1.3

func ResolveIndex(nameOrPath string, cfg *RepoConfig) string

ResolveIndex returns the URL/path for a short name or raw index value.

func ValidateChecksum added in v1.1.3

func ValidateChecksum(path, expected string) error

ValidateChecksum compares file sha256 to expected hex checksum (if provided).

Types

type Docs

type Docs struct {
	GettingStarted string `yaml:"getting_started,omitempty" json:"getting_started,omitempty"`
	APIReference   string `yaml:"api_reference,omitempty" json:"api_reference,omitempty"`
	Examples       string `yaml:"examples,omitempty" json:"examples,omitempty"`
}

Docs contains documentation links

type Examples

type Examples struct {
	Scenarios []string `yaml:"scenarios,omitempty" json:"scenarios,omitempty"`
	Providers []string `yaml:"providers,omitempty" json:"providers,omitempty"`
	UseCases  []string `yaml:"use_cases,omitempty" json:"use_cases,omitempty"`
}

Examples contains example data for quick testing

type FileSpec

type FileSpec struct {
	Path     string `yaml:"path" json:"path"`
	Template string `yaml:"template,omitempty" json:"template,omitempty"`
	Content  string `yaml:"content,omitempty" json:"content,omitempty"`
	// Source is an external file path relative to the template directory
	Source     string            `yaml:"source,omitempty" json:"source,omitempty"`
	Condition  string            `yaml:"condition,omitempty" json:"condition,omitempty"`
	ForEach    string            `yaml:"foreach,omitempty" json:"foreach,omitempty"`
	Variables  map[string]string `yaml:"variables,omitempty" json:"variables,omitempty"`
	Executable bool              `yaml:"executable,omitempty" json:"executable,omitempty"`
}

FileSpec defines a file to be generated from the template

type GenerationResult

type GenerationResult struct {
	Success      bool
	ProjectPath  string
	FilesCreated []string
	Errors       []error
	Warnings     []string
	Duration     time.Duration
}

GenerationResult contains the result of template generation

type Generator

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

Generator handles template generation and file creation

func NewGenerator

func NewGenerator(tmpl *Template, loader *Loader) *Generator

NewGenerator creates a new template generator

func (*Generator) Generate

func (g *Generator) Generate(config *TemplateConfig) (*GenerationResult, error)

Generate generates a project from the template

type Hook

type Hook struct {
	Message   string `yaml:"message,omitempty" json:"message,omitempty"`
	Command   string `yaml:"command" json:"command"`
	Condition string `yaml:"condition,omitempty" json:"condition,omitempty"`
	Required  bool   `yaml:"required,omitempty" json:"required,omitempty"`
}

Hook defines a command to run during generation

type HookSet

type HookSet struct {
	PreCreate  []Hook `yaml:"pre_create,omitempty" json:"pre_create,omitempty"`
	PostCreate []Hook `yaml:"post_create,omitempty" json:"post_create,omitempty"`
}

HookSet defines pre and post generation hooks

type Index added in v1.1.3

type Index struct {
	APIVersion string            `yaml:"apiVersion"`
	Kind       string            `yaml:"kind"`
	Metadata   map[string]string `yaml:"metadata,omitempty"`
	Spec       IndexSpec         `yaml:"spec"`
}

Index lists available templates using K8s-style metadata/spec.

func LoadIndex added in v1.1.3

func LoadIndex(path string) (*Index, error)

LoadIndex loads an index from path.

func (*Index) FindEntry added in v1.1.3

func (idx *Index) FindEntry(name, version string) (*IndexEntry, error)

FindEntry finds an entry by name (and optional version).

type IndexEntry added in v1.1.3

type IndexEntry struct {
	Name        string   `yaml:"name"`
	Version     string   `yaml:"version"`
	Description string   `yaml:"description,omitempty"`
	Tags        []string `yaml:"tags,omitempty"`
	Source      string   `yaml:"source"` // path or URL (file-only for now)
	Checksum    string   `yaml:"checksum,omitempty"`
	Providers   []string `yaml:"providers,omitempty"`
	Author      string   `yaml:"author,omitempty"`
}

IndexEntry describes a remote template.

type IndexSpec added in v1.1.3

type IndexSpec struct {
	Entries []IndexEntry `yaml:"entries"`
}

IndexSpec holds template entries.

type Loader

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

Loader handles loading templates from various sources

func NewLoader

func NewLoader(cacheDir string) *Loader

NewLoader creates a new template loader

func (*Loader) ListBuiltIn

func (l *Loader) ListBuiltIn() ([]TemplateInfo, error)

ListBuiltIn returns a list of all built-in templates

func (*Loader) Load

func (l *Loader) Load(name string) (*Template, error)

Load loads a template by name from any source

func (*Loader) LoadBuiltIn

func (l *Loader) LoadBuiltIn(name string) (*Template, error)

LoadBuiltIn loads a built-in template

func (*Loader) LoadFromFile

func (l *Loader) LoadFromFile(path string) (*Template, error)

LoadFromFile loads a template from a file path

func (*Loader) LoadFromRegistry added in v1.1.3

func (l *Loader) LoadFromRegistry(ref string) (*Template, error)

LoadFromRegistry fetches a template using the default index and cache.

func (*Loader) ReadTemplateFile

func (l *Loader) ReadTemplateFile(templateName, filePath string) ([]byte, error)

ReadTemplateFile reads a template file from the built-in templates

type RepoConfig added in v1.1.3

type RepoConfig struct {
	Repos map[string]string `yaml:"repos"`
}

RepoConfig stores named template repositories.

func LoadRepoConfig added in v1.1.3

func LoadRepoConfig(path string) (*RepoConfig, error)

LoadRepoConfig reads repo config from disk. Missing files return defaults.

func (*RepoConfig) Add added in v1.1.3

func (cfg *RepoConfig) Add(name, url string)

Add inserts or updates a repo entry.

func (*RepoConfig) Remove added in v1.1.3

func (cfg *RepoConfig) Remove(name string)

Remove deletes a repo entry (default repo is re-added via ensureDefaults).

func (*RepoConfig) Save added in v1.1.3

func (cfg *RepoConfig) Save(path string) error

Save writes the repo config to disk, creating parent directories as needed.

type Requirements

type Requirements struct {
	CLIVersion string   `yaml:"cli_version,omitempty" json:"cli_version,omitempty"`
	Tools      []string `yaml:"tools,omitempty" json:"tools,omitempty"`
}

Requirements defines template requirements

type Template

type Template struct {
	APIVersion string           `yaml:"apiVersion" json:"apiVersion"`
	Kind       string           `yaml:"kind" json:"kind"`
	Metadata   TemplateMetadata `yaml:"metadata" json:"metadata"`
	Spec       TemplateSpec     `yaml:"spec" json:"spec"`
	BaseDir    string           `yaml:"-" json:"-"` // directory containing the template file (for source resolution)
}

Template represents a project template configuration

type TemplateConfig

type TemplateConfig struct {
	ProjectName string
	OutputDir   string
	Variables   map[string]interface{}
	Template    *Template
}

TemplateConfig holds the configuration for template generation

type TemplateFile added in v1.1.3

type TemplateFile struct {
	Path    string `yaml:"path"`
	Content string `yaml:"content"`
}

TemplateFile is a single file in a template package.

type TemplateInfo

type TemplateInfo struct {
	Name        string
	Version     string
	Description string
	Author      string
	Tags        []string
	Source      TemplateSource
	Verified    bool
	Downloads   int
	Path        string
}

TemplateInfo contains metadata about a template

type TemplateMetadata

type TemplateMetadata struct {
	Name        string            `yaml:"name" json:"name"`
	Labels      map[string]string `yaml:"labels,omitempty" json:"labels,omitempty"`
	Annotations map[string]string `yaml:"annotations,omitempty" json:"annotations,omitempty"`
}

TemplateMetadata contains template identification and metadata

type TemplatePackage added in v1.1.3

type TemplatePackage struct {
	Files []TemplateFile `yaml:"files"`
}

TemplatePackage holds files to render.

func LoadTemplatePackage added in v1.1.3

func LoadTemplatePackage(path string) (*TemplatePackage, error)

LoadTemplatePackage loads a template package from path.

type TemplateSource

type TemplateSource int

TemplateSource represents where a template comes from

const (
	SourceBuiltIn TemplateSource = iota
	SourceRemote
	SourceLocal
)

type TemplateSpec

type TemplateSpec struct {
	Variables []Variable    `yaml:"variables,omitempty" json:"variables,omitempty"`
	Files     []FileSpec    `yaml:"files" json:"files"`
	Hooks     *HookSet      `yaml:"hooks,omitempty" json:"hooks,omitempty"`
	Examples  *Examples     `yaml:"examples,omitempty" json:"examples,omitempty"`
	Docs      *Docs         `yaml:"docs,omitempty" json:"docs,omitempty"`
	Requires  *Requirements `yaml:"requires,omitempty" json:"requires,omitempty"`
}

TemplateSpec defines the template specification

type Variable

type Variable struct {
	Name        string      `yaml:"name" json:"name"`
	Description string      `yaml:"description,omitempty" json:"description,omitempty"`
	Type        string      `yaml:"type,omitempty" json:"type,omitempty"` // string, number, boolean, array, select
	Default     interface{} `yaml:"default,omitempty" json:"default,omitempty"`
	Required    bool        `yaml:"required,omitempty" json:"required,omitempty"`
	Validation  string      `yaml:"validation,omitempty" json:"validation,omitempty"` // regex pattern
	Options     []string    `yaml:"options,omitempty" json:"options,omitempty"`       // for select/array types
	Prompt      string      `yaml:"prompt,omitempty" json:"prompt,omitempty"`         // interactive prompt text
}

Variable defines a template variable that can be customized

Jump to

Keyboard shortcuts

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