class AmberCLI::Documentation::GenerationSystem

Overview

Code Generation System

Amber CLI provides a flexible and configurable code generation system that can create models, controllers, views, and custom components.

Built-in Generators

The CLI includes several built-in generators:

Model Generator

Creates a new model with associated files:

amber generate model User name:String email:String

Generates:

Controller Generator

Creates a new controller:

amber generate controller Posts

Generates:

Scaffold Generator

Creates a complete CRUD resource:

amber generate scaffold Post title:String content:Text

Generates model, controller, views, and migration files.

Custom Generators

You can create custom generators by defining generator configuration files in JSON or YAML format. These files specify templates, transformations, and post-generation commands.

Generator Configuration Format

name: "my_custom_generator"
description: "Generates custom components"
template_variables:
  author: "Your Name"
  license: "MIT"
naming_conventions:
  snake_case: "underscore_separated"
  pascal_case: "CamelCase"
file_generation_rules:
  service:
    - template: "service_template"
      output_path: "src/services/{{snake_case}}_service.cr"
post_generation_commands:
  - "crystal tool format {{output_path}}"

Word Transformations

The generator system includes intelligent word transformations:

Defined in:

amber_cli/documentation.cr