On this page
article
Templates Overview
Overview of the template structure
The templates directory is the core of the generator project, it contains all the template files used to generate the cli scaffolding.
Structure
The directory is organized into three main categories:
common/: Contains files that are always included in every generated project, regardless of the selected type or features (e.g.,LICENSE,Makefile,README.md).types/: Contains different project “blueprints”. These are mutually exclusive. For example:basic: A simple CLI structure.interactive: A CLI with interactive prompts.
features/: Contains optional components that can be added to a project. A common example is thepages/wwwfeature which adds a documentation website.
Template Rendering
Files within these directories can be either static files or dynamic templates:
- Go Templates (
.tmpl): Files ending with the.tmplextension are processed using Go’stext/templatepackage. The extension is removed during generation. - Static Files: Files without the
.tmplextension are copied directly to the output directory without any modifications.
Embedding
The entire templates/ directory is embedded into the Go binary using the embed package, specifically in templates/main.go. This ensures that the generator is a single, self-contained binary that doesn’t depend on external files at runtime.
package templates
import "embed"
//go:embed all:*
var FolderFS embed.FS