Class: Aidp::Setup::Devcontainer::Generator
- Inherits:
-
Object
- Object
- Aidp::Setup::Devcontainer::Generator
- Defined in:
- lib/aidp/setup/devcontainer/generator.rb
Overview
Generates or updates devcontainer.json based on wizard configuration
Defined Under Namespace
Classes: GenerationError
Instance Method Summary collapse
-
#build_features_list(wizard_config) ⇒ Hash
Build list of devcontainer features from wizard selections.
-
#build_post_commands(wizard_config) ⇒ String?
Build post-create/start commands.
-
#generate(wizard_config, existing = nil) ⇒ Hash
Generate complete devcontainer configuration.
-
#initialize(project_dir, aidp_config = {}) ⇒ Generator
constructor
A new instance of Generator.
-
#merge_with_existing(new_config, existing) ⇒ Hash
Merge new configuration with existing, preserving user customizations.
Constructor Details
#initialize(project_dir, aidp_config = {}) ⇒ Generator
Returns a new instance of Generator.
13 14 15 16 |
# File 'lib/aidp/setup/devcontainer/generator.rb', line 13 def initialize(project_dir, aidp_config = {}) @project_dir = project_dir @aidp_config = aidp_config end |
Instance Method Details
#build_features_list(wizard_config) ⇒ Hash
Build list of devcontainer features from wizard selections
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/aidp/setup/devcontainer/generator.rb', line 97 def build_features_list(wizard_config) features = {} # GitHub CLI (for all provider selections) if wizard_config[:providers]&.any? features["ghcr.io/devcontainers/features/github-cli:1"] = {} end # Ruby (for RSpec, StandardRB) if needs_ruby?(wizard_config) features["ghcr.io/devcontainers/features/ruby:1"] = { "version" => wizard_config[:ruby_version] || "3.2" } end # Node.js (for Jest, Playwright, ESLint) if needs_node?(wizard_config) features["ghcr.io/devcontainers/features/node:1"] = { "version" => wizard_config[:node_version] || "lts" } end # Playwright (for browser automation) if wizard_config[:interactive_tools]&.include?("playwright") features["ghcr.io/devcontainers-contrib/features/playwright:2"] = {} end # Docker-in-Docker (if requested) if wizard_config[:features]&.include?("docker") features["ghcr.io/devcontainers/features/docker-in-docker:2"] = {} end # Additional custom features wizard_config[:additional_features]&.each do |feature| features[feature] = {} end features end |
#build_post_commands(wizard_config) ⇒ String?
Build post-create/start commands
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/aidp/setup/devcontainer/generator.rb', line 140 def build_post_commands(wizard_config) commands = [] # Ruby dependencies if needs_ruby?(wizard_config) commands << "bundle install" end # Node dependencies if needs_node?(wizard_config) commands << "npm install" end # Custom post-create commands if wizard_config[:post_create_commands]&.any? commands.concat(wizard_config[:post_create_commands]) end commands.empty? ? nil : commands.join(" && ") end |
#generate(wizard_config, existing = nil) ⇒ Hash
Generate complete devcontainer configuration
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/aidp/setup/devcontainer/generator.rb', line 22 def generate(wizard_config, existing = nil) Aidp.log_debug("devcontainer_generator", "generating configuration", has_existing: !existing.nil?, wizard_keys: wizard_config.keys) base_config = build_base_config(wizard_config) feature_config = build_features_config(wizard_config) port_config = build_ports_config(wizard_config) env_config = build_env_config(wizard_config) command_config = build_commands_config(wizard_config) customization_config = build_customizations_config(wizard_config) config = base_config .merge(feature_config) .merge(port_config) .merge(env_config) .merge(command_config) .merge(customization_config) if existing merge_with_existing(config, existing) else config end end |
#merge_with_existing(new_config, existing) ⇒ Hash
Merge new configuration with existing, preserving user customizations
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/aidp/setup/devcontainer/generator.rb', line 52 def merge_with_existing(new_config, existing) Aidp.log_debug("devcontainer_generator", "merging configurations", new_keys: new_config.keys, existing_keys: existing.keys) merged = existing.dup # Merge features (combine arrays/hashes) merged["features"] = merge_features( new_config["features"], existing["features"] ) # Merge ports (combine arrays, deduplicate) merged["forwardPorts"] = merge_ports( new_config["forwardPorts"], existing["forwardPorts"] ) # Merge port attributes merged["portsAttributes"] = (existing["portsAttributes"] || {}) .merge(new_config["portsAttributes"] || {}) # Merge environment variables merged["containerEnv"] = (existing["containerEnv"] || {}) .merge(new_config["containerEnv"] || {}) # Merge customizations merged["customizations"] = merge_customizations( new_config["customizations"], existing["customizations"] ) # Update AIDP metadata merged["_aidp"] = new_config["_aidp"] # Preserve user-managed fields preserve_user_fields(merged, existing) merged end |