Class: Discharger::SetupRunner::Commands::AsdfCommand

Inherits:
BaseCommand
  • Object
show all
Defined in:
lib/discharger/setup_runner/commands/asdf_command.rb

Instance Attribute Summary

Attributes inherited from BaseCommand

#app_root, #config, #logger

Instance Method Summary collapse

Methods inherited from BaseCommand

#initialize

Constructor Details

This class inherits a constructor from Discharger::SetupRunner::Commands::BaseCommand

Instance Method Details

#can_execute?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/discharger/setup_runner/commands/asdf_command.rb', line 51

def can_execute?
  File.exist?(File.join(app_root, ".tool-versions"))
end

#descriptionObject



55
56
57
# File 'lib/discharger/setup_runner/commands/asdf_command.rb', line 55

def description
  "Install tool versions with asdf"
end

#executeObject



9
10
11
12
13
14
15
16
17
18
19
20
21
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
47
48
49
# File 'lib/discharger/setup_runner/commands/asdf_command.rb', line 9

def execute
  log "Install tool-versions dependencies via ASDF"

  unless system_quiet("which asdf")
    log "asdf not installed. Run `brew install asdf` if you want bin/setup to ensure versions are up-to-date"
    return
  end

  tools_versions_file = File.join(app_root, ".tool-versions")
  return log("No .tool-versions file found") unless File.exist?(tools_versions_file)

  dependencies = File.read(tools_versions_file).split("\n")
  installables = []

  # Check for nodejs plugin
  unless system_quiet("asdf plugin list | grep nodejs")
    node_deps = dependencies.select { |item| item.match?(/node/) }
    if node_deps.any?
      ask_to_install "asdf to manage Node JS" do
        installables.concat(node_deps)
        system! "asdf plugin add nodejs https://github.com/asdf-vm/asdf-nodejs.git"
      end
    end
  end

  # Check for ruby plugin
  unless system_quiet("asdf plugin list | grep ruby")
    ruby_deps = dependencies.select { |item| item.match?(/ruby/) }
    if ruby_deps.any?
      ask_to_install "asdf to manage Ruby" do
        installables.concat(ruby_deps)
        system! "asdf plugin add ruby https://github.com/asdf-vm/asdf-ruby.git"
      end
    end
  end

  # Install all versions
  installables.each do |name_version|
    system! "asdf install #{name_version}"
  end
end