Processors vs Plugins
When to use processors versus plugins
Processors vs Plugins
Processors and plugins serve different purposes in CyanPrint. Understanding when to use each is key to effective template design.
Quick Comparison
| Aspect | Processors | Plugins |
|---|---|---|
| When | During file generation | After file generation |
| What | Transform file content | Execute actions |
| Input | Template files + variables | Generated project |
| Output | Transformed files | Side effects |
| Examples | Variable substitution, code gen | Git init, npm install |
Processors
Processors handle file transformation during generation.
When to Use
- Variable substitution in files
- Template engine processing (Eta, Handlebars)
- Code generation (GraphQL, Protobuf)
- File content transformation
- Custom file processing logic
How They Work
Example
return {processors: [{name: 'cyan/default',files: [{ root: 'templates', glob: '**/*.md', exclude: [], type: GlobType.Template }],config: {vars: { name: 'my-project' }}}]};
Template file:
# var__name__Welcome to var__name__!
Generated file:
# my-projectWelcome to my-project!
Plugins
Plugins handle post-generation actions after files are created.
When to Use
- Git repository initialization
- Dependency installation
- Running scripts
- External service integration
- IDE configuration
- File permissions
How They Work
Example
return {processors: [/* ... */],plugins: [{name: 'cyan/init-git',config: { commitMessage: 'Initial commit' }},{name: 'cyan/npm-install',config: { packageManager: 'pnpm' }}]};
Decision Flow
Common Patterns
Template with Variable Substitution
Use processor:
processors: [{name: 'cyan/default',files: [{ root: 'templates', glob: '**/*', exclude: [], type: GlobType.Template }],config: { vars: { name, version } }}]
Code Generation
Use custom processor:
processors: [{name: 'myorg/graphql-codegen',files: [{ root: 'schemas', glob: '**/*.graphql', exclude: [], type: GlobType.Template }],config: { generateTypes: true, outputDir: 'src/generated' }}]
Git Initialization
Use plugin:
plugins: [{name: 'cyan/init-git',config: { commitMessage: 'Initial commit' }}]
Install Dependencies
Use plugin:
plugins: [{name: 'cyan/npm-install',config: { packageManager: 'pnpm' }}]
Creating Custom
Custom Processor
Create when you need specialized file processing:
- Define processor package
- Implement
IProcessorinterface - Register with registry
- Use in templates
See Processor Development for details.
Custom Plugin
Create when you need post-generation actions:
- Define plugin package
- Implement
IPlugininterface - Register with registry
- Use in templates
See Plugin Development for details.
Best Practices
- Use default processor for standard templating
- Create custom processors for specialized file processing
- Use plugins for actions that modify project state
- Keep processors focused on file transformation
- Keep plugins focused on side effects
Processors should be pure functions of input files and variables. Plugins handle impure operations like filesystem changes and external services.
Related
- Default Processor - How cyan/default works
- Processor Development - Creating custom processors
- Plugin Development - Creating custom plugins
- Use Custom Processor - How-to guide