Class: Shadwire::Commands::Init
- Inherits:
-
Object
- Object
- Shadwire::Commands::Init
- Defined in:
- lib/shadwire/commands/init.rb
Overview
Bootstraps a consuming Rails app: writes shadwire.json, installs the base files, and applies the base gems + the Tailwind @import (confirm-then-apply, auto on yes:). Idempotent on re-run; --force resets shadwire.json.
Constant Summary collapse
- CLI_GEM =
The CLI gem is a development-time tool for the app, deliberately kept out of registry.json: the registry's gems are what the components need at runtime, and installed files carry no Shadwire dependency.
Binstub::GEM
- CLI_GEM_GROUP =
"development"
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(root:, registry: nil, yes: false, force: false, json: false, ui: UI.new(yes:), runner: Dependencies::DEFAULT_RUNNER) ⇒ Init
constructor
A new instance of Init.
Constructor Details
#initialize(root:, registry: nil, yes: false, force: false, json: false, ui: UI.new(yes:), runner: Dependencies::DEFAULT_RUNNER) ⇒ Init
Returns a new instance of Init.
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/shadwire/commands/init.rb', line 17 def initialize(root:, registry: nil, yes: false, force: false, json: false, ui: UI.new(yes:), runner: Dependencies::DEFAULT_RUNNER) @root = root.to_s @registry_override = registry @yes = yes @force = force @json = json @ui = ui @runner = runner end |
Instance Method Details
#call ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/shadwire/commands/init.rb', line 28 def call project = Project.new(@root) project.raise_unless_rails! config = build_config client = RegistryClient.new(config.registry) base = client.index.fetch("base") report = Installer.new(@root, overwrite: :always).install(base.fetch("files")) deps = Dependencies.new(project, runner: @runner) confirm = ->(desc) { @ui.confirm?(desc) } base_gems = deps.ensure_gems(Array(base["gems"]), yes: @yes, confirm:) cli_gem = deps.ensure_gems([CLI_GEM], yes: @yes, confirm:, group: CLI_GEM_GROUP) gems = merge_gem_results(base_gems, cli_gem) tailwind = deps.ensure_tailwind_import( vendor_css_target(config, base), css_entry: config.tailwind_css, yes: @yes, confirm: ) binstub = write_binstub(cli_gem) config.save warn_missing_stack(project) result = { config:, report:, gems:, gem_results: [base_gems, cli_gem], tailwind:, binstub: } emit(result) # Passed separately, not merged: each result carries its own group, so # the recovery command it suggests matches the one that failed. Dependencies.raise_on_failure!(base_gems, cli_gem) result end |