Class: Rails::Worktrees::PostCreateRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/rails/worktrees/post_create_runner.rb

Overview

Runs post-create setup steps in a newly created worktree. Steps run in order: credential linking, bundle install, yarn install, db:prepare (development), db:prepare (test), assets:precompile (test), assets:clobber. rubocop:disable Metrics/ClassLength

Constant Summary collapse

STEPS =
[
  { id: :bundle, argv: %w[bundle install],
    header: '๐Ÿ“ฆ Installing gems...' },
  { id: :yarn, argv: %w[yarn install],
    header: '๐Ÿงถ Installing JS dependencies...' },
  { id: :db_prepare, argv: %w[bin/rails db:prepare],
    header: '๐Ÿ—„๏ธ  Preparing development database...', env: { 'RAILS_ENV' => 'development' } },
  { id: :test_db_prepare, argv: %w[bin/rails db:prepare],
    header: '๐Ÿ—„๏ธ  Preparing test database...', env: { 'RAILS_ENV' => 'test' } },
  { id: :test_assets_precompile, argv: %w[bin/rails assets:precompile],
    header: '๐ŸŽจ Precompiling test assets...', env: { 'RAILS_ENV' => 'test' } },
  { id: :assets_clobber, argv: %w[bin/rails assets:clobber],
    header: '๐Ÿงน Clobbering compiled assets...' }
].freeze
STEP_CONFIG =
{
  bundle: :run_bundle_install,
  yarn: :run_yarn_install,
  db_prepare: :run_db_prepare,
  test_db_prepare: :run_test_db_prepare,
  test_assets_precompile: :run_test_assets_precompile,
  assets_clobber: :run_test_assets_precompile
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(target_dir:, peer_roots:, configuration:, io:, bootstrapped_env: nil) ⇒ PostCreateRunner

Returns a new instance of PostCreateRunner.



34
35
36
37
38
39
40
41
# File 'lib/rails/worktrees/post_create_runner.rb', line 34

def initialize(target_dir:, peer_roots:, configuration:, io:, bootstrapped_env: nil)
  @target_dir    = target_dir
  @peer_roots    = peer_roots
  @configuration = configuration
  @bootstrapped_env = (bootstrapped_env || {}).transform_values(&:to_s)
  @stdout        = io.fetch(:stdout)
  @stderr        = io.fetch(:stderr)
end

Instance Method Details

#call(dry_run: false) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/rails/worktrees/post_create_runner.rb', line 43

def call(dry_run: false)
  return 0 if @configuration.post_create_command == false

  @runtime_env = resolved_runtime_env(dry_run: dry_run)

  return run_custom_command(dry_run: dry_run) if custom_command?

  run_built_in_steps(dry_run: dry_run)
rescue Error => e
  @stderr.puts("โŒ #{e.message}")
  1
end