Scripting
Archetect's scripting system is powered by Rhai, providing dynamic and interactive archetype generation capabilities. The scripting system allows you to create sophisticated logic for user interaction, data validation, and template control.
Overview
The Rhai scripting system in Archetect enables:
- Complex prompting logic with conditional questions
- Data validation and transformation
- Dynamic feature selection based on user choices
- External command execution and integration
- Advanced case transformations and string manipulation
Architecture
// Basic script structure
let context = #{}; // Create context map
// Gather user input
context.service_name = prompt("Service Name:");
// Process and transform data
context.service_snake = snake_case(context.service_name);
// Output context for templates
debug(context);
Scripting Guide Structure
Rhai Basics
Learn the core Rhai language features, data types, control flow, and fundamental concepts needed for archetype scripting.
Prompting
Master the art of interactive user input with various prompt types, validation, and advanced prompting patterns.
Casing
Explore Archetect's powerful case transformation system for generating consistent naming across different programming languages and conventions.
Switches
Learn how to use command-line switches for conditional content generation, enabling flexible archetype behavior without complex prompts.
Rendering
Master the three rendering methods: string rendering for inline templates, directory rendering for file structures, and component rendering for archetype composition.
Logging and Debugging
Learn how to use logging, debugging, and output functions to create informative and debuggable archetypes with proper output stream management.
When to Use Scripts
Use Rhai scripts in your archetypes when you need:
- Progressive prompting - Ask follow-up questions based on previous answers
- Input validation - Ensure user input meets specific requirements
- Feature dependencies - Automatically include related features
- Complex transformations - Generate derived values from user input
- Conditional logic - Include/exclude files based on user choices
Getting Started
- Start with Rhai Basics to understand the language fundamentals
- Learn Prompting to gather user input effectively
- Master Casing to generate proper naming conventions
- Explore Switches for command-line driven conditional logic
- Understand Rendering to output templates, directories, and components
- Learn Logging and Debugging for proper output and debugging techniques
- Build complex scenarios by combining these concepts
The scripting system transforms static templates into dynamic, interactive generators that can adapt to your users' specific needs.