|
| 1 | +# ColdBox CLI - AI Coding Instructions |
| 2 | + |
| 3 | +This is a CommandBox module providing CLI commands for ColdBox framework development. It generates scaffolded code for handlers, models, views, tests, and complete applications with support for both CFML and BoxLang. |
| 4 | + |
| 5 | +## Architecture & Key Components |
| 6 | + |
| 7 | +**Command Structure**: Commands follow CommandBox's hierarchical structure in `/commands/coldbox/` with subcommands in nested folders (e.g., `create/handler.cfc`, `create/model.cfc`). Each command extends `BaseCommand.cfc` which provides common functionality like BoxLang detection and standardized print methods. |
| 8 | + |
| 9 | +**Template System**: Code generation uses text templates in `/templates/` with token replacement (e.g., `|handlerName|`, `|Description|`). Templates are organized by type and language: |
| 10 | +- `/templates/modules/cfml/` - CFML templates |
| 11 | +- `/templates/modules/bx/` - BoxLang templates |
| 12 | +- `/templates/crud/cfml/` vs `/templates/crud/bx/` - Language-specific variants |
| 13 | + |
| 14 | +**BoxLang Detection**: The `isBoxLangProject()` method in `BaseCommand.cfc` detects BoxLang projects via: |
| 15 | +1. Server engine detection (`serverInfo.cfengine` contains "boxlang") |
| 16 | +2. Package.json `testbox.runner` setting |
| 17 | +3. Package.json `language` property |
| 18 | + |
| 19 | +## Development Workflows |
| 20 | + |
| 21 | +**Command Development**: |
| 22 | +- New commands extend `BaseCommand.cfc` and use dependency injection (`property name="utility" inject="utility@coldbox-cli"`) |
| 23 | +- Use standardized print methods: `printInfo()`, `printError()`, `printWarn()`, `printSuccess()` |
| 24 | +- Commands support `--force` for overwriting and `--open` for opening generated files |
| 25 | + |
| 26 | +**Template Management**: |
| 27 | +- Templates use token replacement with `replaceNoCase(content, "|token|", value, "all")` |
| 28 | +- BoxLang conversion uses `toBoxLangClass()` to transform `component` to `class` |
| 29 | +- Resource generation supports both REST and standard handlers via template selection |
| 30 | + |
| 31 | +**Module Dependencies**: The module lazy-loads `testbox-cli` and `commandbox-migrations` via utility methods `ensureTestBoxModule()` and `ensureMigrationsModule()` only when needed. |
| 32 | + |
| 33 | +## Key Patterns & Conventions |
| 34 | + |
| 35 | +**File Generation Logic**: Commands typically: |
| 36 | +1. Resolve and validate paths using `resolvePath()` |
| 37 | +2. Read appropriate templates based on `--rest`, `--boxlang` flags |
| 38 | +3. Perform token replacements for customization |
| 39 | +4. Create directories if they don't exist |
| 40 | +5. Generate additional files (views, tests) based on flags |
| 41 | + |
| 42 | +**Cross-Component Integration**: |
| 43 | +- Models can generate handlers via `--handler` flag |
| 44 | +- Handlers can generate views via `--views` flag |
| 45 | +- Resource commands generate full CRUD scaffolding |
| 46 | +- Migration and seeder generation integrated with model creation |
| 47 | + |
| 48 | +**Error Handling**: Use `BaseCommand` print methods for consistent user feedback and check file existence before operations when `--force` is not specified. |
| 49 | + |
| 50 | +## Testing & Build |
| 51 | + |
| 52 | +**Build Process**: Uses `/build/Build.cfc` task runner with `box scripts` integration. Run `box build:module` for full build or `box format` for code formatting. |
| 53 | + |
| 54 | +**Template Testing**: The `/tests/` directory contains sample module structure for testing generated code patterns. |
0 commit comments