Class: Staticky::CLI::Commands::Generate

Inherits:
Dry::CLI::Command
  • Object
show all
Defined in:
lib/staticky/cli/commands/generate.rb

Instance Method Summary collapse

Instance Method Details

#bundle_command(command, env = {}) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/staticky/cli/commands/generate.rb', line 43

def bundle_command(command, env = {})
  puts "bundle #{command}"

  # We are going to shell out rather than invoking Bundler::CLI.new(command)
  # because `rails new` loads the Thor gem and on the other hand bundler uses
  # its own vendored Thor, which could be a different version. Running both
  # things in the same process is a recipe for a night with paracetamol.
  #
  # Thanks to James Tucker for the Gem tricks involved in this call.
  _bundle_command = Gem.bin_path("bundler", "bundle")

  require "bundler"
  Bundler.with_original_env do
    exec_bundle_command(_bundle_command, command, env)
  end
end

#call(path:) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/staticky/cli/commands/generate.rb', line 30

def call(path:, **)
  path = Pathname.new(path).expand_path

  Staticky.generator.call(path, **)

  Dir.chdir(path) do
    system("cd #{path}")
    system("chmod +x bin/*")
    bundle_command("install")
    bundle_command("exec bin/setup")
  end
end

#exec_bundle_command(bundle_command, command, env) ⇒ Object



60
61
62
63
# File 'lib/staticky/cli/commands/generate.rb', line 60

def exec_bundle_command(bundle_command, command, env)
  full_command = %("#{Gem.ruby}" "#{bundle_command}" #{command})
  system(env, full_command)
end