Template Development
Create reusable project templates with CyanPrint SDK
Template Development
Templates are the core building blocks of CyanPrint. They define how projects are scaffolded, from simple file copying to complex multi-step generators with user interactions.
What is a Template?
A CyanPrint template is a Docker container that:
- Asks questions to collect user preferences
- Processes files using variable substitution
- Generates output in the target directory
Templates can range from simple static file copiers to sophisticated generators with conditional logic, multiple processors, and plugin integrations.
Template Architecture
Components
| Component | Purpose | Examples |
|---|---|---|
| index.ts | Template logic entry point | Question handling, config generation |
| Processors | File processing engines | cyan/default, custom processors |
| Plugins | Post-generation actions | Git initialization, dependency installation |
| Template Files | Source files to process | .md, .ts, .json templates |
Learning Path
Start Here: Tutorials
Follow the tutorials to learn template development step by step:
- Blank Template - Create your first template
- Adding Variables - Add variable substitution
- Changing Glob Patterns - Control file processing
- Asking Questions - Collect user input
New to CyanPrint? Start with the Introduction to understand the platform architecture.
How-To Guides
Task-oriented guides for common scenarios:
- Ask Checkbox Questions
- Ask Confirm Questions
- Ask Password Questions
- Validate User Input
- Push to Registry
- Add Plugins
Reference
Technical documentation for the SDK:
- IInquirer API - All question types
- Cyan Config - Configuration structure
- Globbing Patterns - File matching syntax
- Type Definitions - SDK types
Explanation
Deep dives into concepts and architecture:
- Determinism - How reproducible generation works
- Default Processor - Eta templating explained
- Container Paths - Path mechanics in containers
Quick Example
Here's a minimal template that asks for a project name and generates a README:
import { StartTemplateWithLambda, GlobType, IInquirer, IDeterminism } from '@atomicloud/cyan-sdk';StartTemplateWithLambda(async (i: IInquirer, d: IDeterminism) => {// Ask user for project nameconst name = await i.text('Project name?', 'project.name', 'Enter project name');return {processors: [{name: 'cyan/default',files: [{ root: 'template', glob: '**/*', exclude: [], type: GlobType.Template }],config: { vars: { name } }}]};});
Template file (template/README.md):
# var__name__Welcome to your new project!
The var__name__ syntax is used by the default processor for variable substitution. Variables defined in config.vars are accessible using the var__<variableName>__ pattern. See the Default Processor explanation for more details.