Interactive CLI tool for migrating Jinja templates to new design layouts. Automatically analyzes your existing templates and helps you reorganize them with new structure, variable names, and block mappings.
- Smart Analysis - Automatically discovers variables, blocks, and template structure using Jinja2 AST
- Interactive Mapping - Configure variable and block mappings on-the-fly
- Flexible Paths - Choose new file locations with intelligent suggestions
- Auto Mode - Fully automated migration with sensible defaults
- Dry Run - Preview changes before applying them
- Migration Reports - Detailed reports of all changes made
pip install -r requirements.txt
- Create config file:
python migrator.py --config migration_config.yaml
-
Edit the generated config to set your source/target directories
-
Run migration:
# Interactive mode
python migrator.py
# Auto mode (no prompts)
python migrator.py --auto
# Preview changes first
python migrator.py --dry-run
# Basic migration with interaction
python migrator.py
# Migrate specific templates
python migrator.py -t index.html -t user/profile.html
# Automatic migration with report
python migrator.py --auto --report
# Preview what would change
python migrator.py --dry-run
Simple YAML config with minimal required settings:
source_dir: "./old_templates"
target_dir: "./new_templates"
new_base_template: "layouts/base.html"
exclude_patterns:
- ".*_backup\\.html$"
- "temp_.*\\.html$"
auto_preserve_blocks: true
auto_map_variables: false
- Discovery - Scans all templates to find variables and blocks
- Mapping - Interactively or automatically maps old names to new ones
- Path Selection - Choose new file locations for each template
- Migration - Generates new templates with updated structure
- Reporting - Creates detailed migration report
For each template, choose:
- Keep same path
- Use suggested path (e.g.,
index.html
→pages/index.html
) - Enter custom path
- Skip template
- Review all discovered variables
- Rename as needed (e.g.,
user_name
→username
) - Auto-suggestions for common patterns
- Preserve important blocks
- Rename blocks (e.g.,
content
→main_content
) - Automatic mapping for common block names
Use --auto
flag for fully automated migration:
- Applies sensible path suggestions
- Uses common variable name mappings
- Preserves all blocks with standard renames
- No user interaction required
Migrated templates include:
- New
extends
directive - Preserved blocks with new names
- Updated variable references
- Migration comments for tracking
Generated with Sonnet4
MIT License