Documentation
¶
Index ¶
- Constants
- Variables
- func ScaffoldBuiltIn(logger *zerolog.Logger, templateName, destDir, workflowName string, ...) error
- type Cache
- func (c *Cache) InvalidateTemplateList(source RepoSource)
- func (c *Cache) IsTarballCached(source RepoSource, sha string) bool
- func (c *Cache) LoadStaleTemplateList(source RepoSource) []TemplateSummary
- func (c *Cache) LoadTemplateList(source RepoSource) ([]TemplateSummary, bool)
- func (c *Cache) SaveTemplateList(source RepoSource, templates []TemplateSummary, treeSHA string) error
- func (c *Cache) TarballPath(source RepoSource, sha string) string
- type Client
- func (c *Client) DiscoverTemplates(source RepoSource) ([]TemplateSummary, error)
- func (c *Client) DiscoverTemplatesWithSHA(source RepoSource) (*DiscoverTemplatesResult, error)
- func (c *Client) DownloadAndExtractTemplate(source RepoSource, templatePath, destDir string, exclude []string, ...) error
- func (c *Client) DownloadAndExtractTemplateFromCache(tarballPath, templatePath, destDir string, exclude []string, ...) error
- func (c *Client) DownloadTarball(source RepoSource, destPath string) error
- type DiscoverTemplatesResult
- type Registry
- type RepoSource
- type TemplateMetadata
- type TemplateSummary
- type WorkflowDirEntry
Constants ¶
const CategoryWorkflow = "workflow"
CategoryWorkflow is the category value for installable workflow templates.
const (
TemplateCacheDir = "template-cache"
)
Variables ¶
var BuiltInGoTemplate = TemplateSummary{ TemplateMetadata: TemplateMetadata{ Kind: "building-block", Name: "hello-world-go", Title: "Hello World (Go)", Description: "A minimal cron-triggered workflow to get started from scratch", Language: "go", Category: "workflow", Capabilities: []string{"cron"}, Author: "Chainlink", License: "MIT", Tags: []string{"cron", "starter", "minimal"}, }, Path: "builtin/hello-world-go", BuiltIn: true, }
BuiltInGoTemplate is the embedded hello-world Go template that is always available.
var BuiltInTSTemplate = TemplateSummary{ TemplateMetadata: TemplateMetadata{ Kind: "building-block", Name: "hello-world-ts", Title: "Hello World (TypeScript)", Description: "A minimal cron-triggered workflow to get started from scratch", Language: "typescript", Category: "workflow", Capabilities: []string{"cron"}, Author: "Chainlink", License: "MIT", Tags: []string{"cron", "starter", "minimal"}, }, Path: "builtin/hello-world-ts", BuiltIn: true, }
BuiltInTSTemplate is the embedded hello-world TypeScript template that is always available.
Functions ¶
func ScaffoldBuiltIn ¶
func ScaffoldBuiltIn(logger *zerolog.Logger, templateName, destDir, workflowName string, preserveExisting bool) error
ScaffoldBuiltIn extracts the appropriate embedded hello-world template to destDir, renaming the workflow directory to the user's workflow name. When preserveExisting is true, files that already exist at the target path are left untouched (used when adding a workflow to an existing project, so project-level files are not overwritten).
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache manages template list and tarball caching under the CLI config directory.
func NewCacheWithDir ¶
NewCacheWithDir creates a Cache with a specific directory (for testing).
func (*Cache) InvalidateTemplateList ¶
func (c *Cache) InvalidateTemplateList(source RepoSource)
InvalidateTemplateList removes the cached template list for a repo source, forcing a fresh fetch on the next ListTemplates call.
func (*Cache) IsTarballCached ¶
func (c *Cache) IsTarballCached(source RepoSource, sha string) bool
IsTarballCached checks if a tarball is cached and not expired.
func (*Cache) LoadStaleTemplateList ¶
func (c *Cache) LoadStaleTemplateList(source RepoSource) []TemplateSummary
LoadStaleTemplateList loads templates even if stale (for offline fallback).
func (*Cache) LoadTemplateList ¶
func (c *Cache) LoadTemplateList(source RepoSource) ([]TemplateSummary, bool)
LoadTemplateList loads the cached template list for a repo. Returns nil if cache is missing or stale.
func (*Cache) SaveTemplateList ¶
func (c *Cache) SaveTemplateList(source RepoSource, templates []TemplateSummary, treeSHA string) error
SaveTemplateList saves the template list to cache.
func (*Cache) TarballPath ¶
func (c *Cache) TarballPath(source RepoSource, sha string) string
TarballPath returns the path where a tarball should be cached.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client handles GitHub API interactions for template discovery and download.
func (*Client) DiscoverTemplates ¶
func (c *Client) DiscoverTemplates(source RepoSource) ([]TemplateSummary, error)
DiscoverTemplates uses the GitHub Tree API to find all template.yaml files, then fetches and parses each one to build the template list.
func (*Client) DiscoverTemplatesWithSHA ¶
func (c *Client) DiscoverTemplatesWithSHA(source RepoSource) (*DiscoverTemplatesResult, error)
DiscoverTemplatesWithSHA is like DiscoverTemplates but also returns the tree SHA.
func (*Client) DownloadAndExtractTemplate ¶
func (c *Client) DownloadAndExtractTemplate(source RepoSource, templatePath, destDir string, exclude []string, preserveExisting bool, onProgress func(string)) error
DownloadAndExtractTemplate downloads the repo tarball and extracts only files under the given templatePath, applying exclude patterns.
func (*Client) DownloadAndExtractTemplateFromCache ¶
func (c *Client) DownloadAndExtractTemplateFromCache(tarballPath, templatePath, destDir string, exclude []string, preserveExisting bool) error
DownloadAndExtractTemplateFromCache extracts from a cached tarball file.
func (*Client) DownloadTarball ¶
func (c *Client) DownloadTarball(source RepoSource, destPath string) error
DownloadTarball downloads the repo tarball to a local file and returns the path.
type DiscoverTemplatesResult ¶
type DiscoverTemplatesResult struct {
Templates []TemplateSummary
TreeSHA string
}
DiscoverTemplatesResult holds the result along with the tree SHA for caching.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry aggregates templates from multiple repos and provides lookup/scaffolding.
func NewRegistry ¶
func NewRegistry(logger *zerolog.Logger, sources []RepoSource) (*Registry, error)
NewRegistry creates a new Registry with the given sources.
func NewRegistryWithCache ¶
func NewRegistryWithCache(logger *zerolog.Logger, client *Client, cache *Cache, sources []RepoSource) *Registry
NewRegistryWithCache creates a Registry with an injected cache (for testing).
func (*Registry) GetTemplate ¶
func (r *Registry) GetTemplate(name string, refresh bool) (*TemplateSummary, error)
GetTemplate looks up a template by name from all sources.
func (*Registry) ListTemplates ¶
func (r *Registry) ListTemplates(refresh bool) ([]TemplateSummary, error)
ListTemplates discovers and returns all templates from configured sources. The built-in hello-world template is always included first. If refresh is true, the cache is bypassed.
func (*Registry) ScaffoldTemplate ¶
func (r *Registry) ScaffoldTemplate(tmpl *TemplateSummary, destDir, workflowName string, preserveExisting bool, onProgress func(string)) error
ScaffoldTemplate downloads and extracts a template into destDir, then renames the template's workflow directory to the user's workflow name.
type RepoSource ¶
RepoSource identifies a GitHub repository and ref.
type TemplateMetadata ¶
type TemplateMetadata struct {
Kind string `yaml:"kind"` // "building-block" or "starter-template"
ID string `yaml:"id"` // Unique slug identifier (preferred over name)
Name string `yaml:"name"` // Unique slug identifier (deprecated, use id)
Title string `yaml:"title"` // Human-readable display name
Description string `yaml:"description"` // Short description
Language string `yaml:"language"` // "go" or "typescript"
Category string `yaml:"category"` // Template type: "workflow" or "demo-app"
Solutions []string `yaml:"solutions"` // Solution categories (e.g., "defi-vault-operations")
Capabilities []string `yaml:"capabilities"` // CRE capabilities used (e.g., "cron", "http", "chain-read")
Author string `yaml:"author"`
License string `yaml:"license"`
Tags []string `yaml:"tags"` // Searchable tags
Exclude []string `yaml:"exclude"` // Files/dirs to exclude when copying
Networks []string `yaml:"networks"` // Required chain names (e.g., "ethereum-testnet-sepolia")
Workflows []WorkflowDirEntry `yaml:"workflows"` // Workflow directories inside the template
PostInit string `yaml:"postInit"` // Template-specific post-init instructions
ProjectDir string `yaml:"projectDir"` // CRE project directory within the template (e.g., "." or "cre-workflow")
}
TemplateMetadata represents the contents of a template.yaml file.
func (*TemplateMetadata) GetName ¶
func (t *TemplateMetadata) GetName() string
GetName returns the template identifier, preferring ID over Name for backward compatibility.
type TemplateSummary ¶
type TemplateSummary struct {
TemplateMetadata
Path string // Relative path in repo (e.g., "building-blocks/kv-store/kv-store-go")
Source RepoSource // Which repo this came from
BuiltIn bool // True if this is an embedded built-in template
}
TemplateSummary is TemplateMetadata plus location info, populated during discovery.
func BuiltInTemplates ¶
func BuiltInTemplates() []TemplateSummary
BuiltInTemplates returns all built-in templates.
type WorkflowDirEntry ¶
type WorkflowDirEntry struct {
Dir string `yaml:"dir"`
Description string `yaml:"description,omitempty"`
}
WorkflowDirEntry describes a workflow directory inside a template.