Skip to content

Commit ce9470a

Browse files
feat: separate CLI version from Amber framework version
- Remove hardcoded Amber::VERSION that referenced CLI version - Add configurable amber_framework_version to generator system - Update shard.yml.ecr template to use {{amber_framework_version}} variable - Add built-in template variables: cli_version and amber_framework_version - Clean up documentation with :nodoc: directives for internal modules - Hide legacy/internal modules from public documentation - Reduce documentation from 84 to 39 HTML files (58% reduction) - Focus documentation on user-facing commands and comprehensive guides This allows the CLI tool to be versioned independently from the Amber framework version used when creating new applications. Teams can now: - Pin projects to specific Amber framework versions - Test with different framework versions - Maintain compatibility with existing projects - Upgrade the CLI tool without changing framework dependencies
1 parent be8db26 commit ce9470a

31 files changed

+166
-19
lines changed

shard.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@ dependencies:
3535
github: crystal-loot/exception_page
3636
version: ~> 0.2.1
3737

38-
# inflector library has been vendored into src/amber_cli/vendor/inflector/
39-
# with improvements and fixes (foot->feet, tooth->teeth, etc.)
40-
4138
# CLI tool item, specifically for when distributing a compiled binary (like the CLI tool will be)
4239
compiled_license:
4340
github: elorest/compiled_license

src/amber_cli/commands.cr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# :nodoc:
12
require "../version"
23
require "./config"
34

src/amber_cli/config.cr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# :nodoc:
12
require "yaml"
23

34
module Amber::CLI

src/amber_cli/core/base_command.cr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# :nodoc:
12
require "option_parser"
23

34
module AmberCLI::Core

src/amber_cli/core/configurable_generator_manager.cr

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# :nodoc:
12
require "./generator_config"
23
require "./template_engine"
34
require "./word_transformer"
@@ -26,7 +27,10 @@ module AmberCLI::Core
2627

2728
begin
2829
generator_rules.each do |rule|
29-
generated_files = @template_engine.generate_file_from_rule(rule, name, template_dir, template_variables, naming_conventions)
30+
# Get amber framework version from config, defaulting to current stable version
31+
amber_version = template_variables["amber_framework_version"]? || "1.4.0"
32+
33+
generated_files = @template_engine.generate_file_from_rule(rule, name, template_dir, template_variables, naming_conventions, amber_version)
3034

3135
generated_files.each do |file_info|
3236
# Create directory if needed

src/amber_cli/core/generator_config.cr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# :nodoc:
12
require "json"
23
require "yaml"
34

src/amber_cli/core/template_engine.cr

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# :nodoc:
2+
require "ecr"
3+
require "file_utils"
14
require "../exceptions"
25
require "./word_transformer"
36
require "./generator_config"
@@ -24,7 +27,7 @@ module AmberCLI::Core
2427
result
2528
end
2629

27-
def generate_file_from_rule(rule : FileGenerationRule, word : String, template_dir : String, custom_variables : Hash(String, String), naming_conventions : Hash(String, String) = {} of String => String) : Array(NamedTuple(path: String, content: String))
30+
def generate_file_from_rule(rule : FileGenerationRule, word : String, template_dir : String, custom_variables : Hash(String, String), naming_conventions : Hash(String, String) = {} of String => String, amber_framework_version : String = "1.4.0") : Array(NamedTuple(path: String, content: String))
2831
# Check conditions first
2932
if conditions = rule.conditions
3033
return [] of NamedTuple(path: String, content: String) unless meets_conditions?(conditions, custom_variables)
@@ -41,6 +44,10 @@ module AmberCLI::Core
4144
# Build replacement context
4245
replacements = custom_variables.dup
4346

47+
# Add built-in variables
48+
replacements["cli_version"] = AmberCli::VERSION
49+
replacements["amber_framework_version"] = amber_framework_version
50+
4451
# Add word transformations
4552
if transformations = rule.transformations
4653
transformations.each do |placeholder, transformation|

src/amber_cli/core/word_transformer.cr

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# :nodoc:
12
require "../vendor/inflector/inflector"
23

34
module AmberCLI::Core
@@ -70,6 +71,11 @@ module AmberCLI::Core
7071
# Note: "feet" -> "foot" is now fixed in our vendored inflector
7172
}
7273

74+
# Built-in variables that can be used in templates
75+
BUILT_IN_VARIABLES = {
76+
"cli_version" => AmberCli::VERSION,
77+
}
78+
7379
# Transforms a word using the specified transformation type.
7480
#
7581
# Checks for custom conventions first, allowing any transformation to be overridden

src/amber_cli/documentation.cr

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,105 @@ module AmberCLI::Documentation
594594
# include:
595595
# - "./spec/**/*.cr"
596596
# ```
597+
#
598+
# # Configuration Reference
599+
#
600+
# Amber CLI uses several configuration mechanisms to customize behavior
601+
# for different project types and development workflows.
602+
#
603+
# ## Project Configuration (`.amber.yml`)
604+
#
605+
# The `.amber.yml` file in your project root configures project-specific settings:
606+
#
607+
# ```yaml
608+
# database: pg # Database type: pg, mysql, sqlite
609+
# language: slang # Template language: slang, ecr
610+
# model: granite # ORM: granite, jennifer
611+
# watch:
612+
# run:
613+
# build_commands:
614+
# - "crystal build ./src/my_app.cr -o bin/my_app"
615+
# run_commands:
616+
# - "bin/my_app"
617+
# include:
618+
# - "./config/**/*.cr"
619+
# - "./src/**/*.cr"
620+
# ```
621+
#
622+
# ## Generator Configuration
623+
#
624+
# Custom generators can be configured using JSON or YAML files in the
625+
# `generator_configs/` directory:
626+
#
627+
# ### Basic Generator Configuration
628+
#
629+
# ```yaml
630+
# name: "custom_model"
631+
# description: "Generate a custom model with validation"
632+
# template_directory: "templates/models"
633+
# amber_framework_version: "1.4.0" # Amber framework version for new projects
634+
# custom_variables:
635+
# author: "Your Name"
636+
# license: "MIT"
637+
# naming_conventions:
638+
# table_prefix: "app_"
639+
# file_generation_rules:
640+
# - template_file: "model.cr.ecr"
641+
# output_path: "src/models/{{snake_case}}.cr"
642+
# transformations:
643+
# class_name: "pascal_case"
644+
# ```
645+
#
646+
# ### Framework Version Configuration
647+
#
648+
# The `amber_framework_version` setting determines which version of the Amber
649+
# framework gets used when creating new applications. This is separate from the
650+
# CLI tool version and allows you to:
651+
#
652+
# - Pin projects to specific Amber versions
653+
# - Test with different framework versions
654+
# - Maintain compatibility with existing projects
655+
#
656+
# Available template variables:
657+
# - `{{cli_version}}` - Current Amber CLI version
658+
# - `{{amber_framework_version}}` - Configured Amber framework version
659+
# - All word transformations (snake_case, pascal_case, etc.)
660+
#
661+
# ### Advanced Generator Features
662+
#
663+
# #### Conditional File Generation
664+
#
665+
# ```yaml
666+
# file_generation_rules:
667+
# - template_file: "api_spec.cr.ecr"
668+
# output_path: "spec/{{snake_case}}_spec.cr"
669+
# conditions:
670+
# generate_specs: "true"
671+
# ```
672+
#
673+
# #### Custom Transformations
674+
#
675+
# ```yaml
676+
# naming_conventions:
677+
# namespace_prefix: "MyApp::"
678+
# table_prefix: "my_app_"
679+
# transformations:
680+
# full_class_name: "pascal_case" # Will use namespace_prefix
681+
# ```
682+
#
683+
# ## Environment Configuration
684+
#
685+
# Environment-specific settings go in `config/environments/`:
686+
#
687+
# ```yaml
688+
# # config/environments/development.yml
689+
# database_url: "postgres://localhost/myapp_development"
690+
# amber_framework_version: "1.4.0"
691+
#
692+
# # config/environments/production.yml
693+
# database_url: ENV["DATABASE_URL"]
694+
# amber_framework_version: "1.4.0"
695+
# ```
597696
class ConfigurationReference
598697
end
599698

src/amber_cli/exceptions.cr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# :nodoc:
12
module AmberCLI::Exceptions
23
class TemplateError < Exception
34
def initialize(message : String)

0 commit comments

Comments
 (0)