Customizing Copier templates for project generation.
1
2
3
4
5
6
templates/
βββ copier.yml # Main configuration
βββ hooks/
β βββ pre_gen.py # Before generation
β βββ post_gen.py # After generation
βββ {{ project_name }}/ # Template directory
Edit copier.yml:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
# Add a new question
feature_flags:
type: bool
help: Include feature flag support?
default: false
api_style:
type: str
help: API architecture style
choices:
- rest
- graphql
- grpc
default: rest
Use Jinja conditionals in directory names:
1
2
3
4
5
6
7
8
9
{{ project_name }}/
βββ src/
β βββ index.ts.jinja
β βββ {% if api_style == 'graphql' %}
β β βββ schema.graphql.jinja
β β {% endif %}
β βββ {% if feature_flags %}
β βββ flags.ts.jinja
β {% endif %}
1
2
3
4
5
6
// {{ project_name }}/src/config.ts
export const config = {
name: '{{ project_name }}',
owner: '{{ owner }}',
version: '{{ version | default("1.0.0") }}',
};
1
2
3
4
5
6
7
{% if include_sea_governance %}
import { SeaValidator } from '@sea/validator';
export function validateOnStartup() {
return SeaValidator.check();
}
{% endif %}
1
2
3
{% for dep in dependencies %}
import { {{ dep.export }} } from '{{ dep.package }}';
{% endfor %}
1
2
3
4
5
6
7
8
9
10
11
12
# hooks/pre_gen.py
import os
import sys
def validate_project_name():
name = os.environ.get('project_name', '')
if not name.replace('-', '').isalnum():
print("Error: Project name must be alphanumeric with hyphens")
sys.exit(1)
if __name__ == '__main__':
validate_project_name()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# hooks/post_gen.py
import subprocess
import os
def install_dependencies():
os.chdir(os.environ['project_name'])
subprocess.run(['pnpm', 'install'], check=True)
def setup_git():
subprocess.run(['git', 'init'], check=True)
subprocess.run(['git', 'add', '.'], check=True)
if __name__ == '__main__':
install_dependencies()
setup_git()
print("β
Project setup complete!")
Add SEA-specific questions:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# SEAβ’ Governance Questions
include_sea_governance:
type: bool
help: Enable SEAβ’ DSL validation?
default: true
sea_bounded_context:
type: str
help: SEAβ’ bounded context
choices:
- semantic-core
- cognitive-extension
- architectural-governance
- developer-tooling
default: developer-tooling
when: '{{ include_sea_governance }}'
include_calm_validation:
type: bool
help: Include CALM architecture validation?
default: true
when: '{{ include_sea_governance }}'
1
2
3
4
5
6
7
8
# Test with specific answers
copier copy ./templates ./test-output \
--data project_name=test-project \
--data owner=test-team \
--data include_sea_governance=true
# Compare output
diff -r ./expected ./test-output