Class: Hanami::CLI::Commands::Gem::New Private

Inherits:
Hanami::CLI::Command show all
Defined in:
lib/hanami/cli/commands/gem/new.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Since:

  • 2.0.0

Instance Method Summary collapse

Methods inherited from Hanami::CLI::Command

new

Constructor Details

#initialize(fs:, inflector:, bundler: CLI::Bundler.new(fs: fs), generator: Generators::Gem::App.new(fs: fs, inflector: inflector), system_call: SystemCall.new, **opts) ⇒ New

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of New.

Since:

  • 2.0.0



65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/hanami/cli/commands/gem/new.rb', line 65

def initialize(
  fs:, inflector:,
  bundler: CLI::Bundler.new(fs: fs),
  generator: Generators::Gem::App.new(fs: fs, inflector: inflector),
  system_call: SystemCall.new,
  **opts
)
  super(fs: fs, inflector: inflector, **opts)
  @bundler = bundler
  @generator = generator
  @system_call = system_call
end

Instance Method Details

#call(app:, head: HEAD_DEFAULT, skip_install: SKIP_INSTALL_DEFAULT, skip_assets: SKIP_ASSETS_DEFAULT) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Raises:

Since:

  • 2.0.0



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/hanami/cli/commands/gem/new.rb', line 84

def call(app:, head: HEAD_DEFAULT, skip_install: SKIP_INSTALL_DEFAULT, skip_assets: SKIP_ASSETS_DEFAULT, **)
  app = inflector.underscore(app)

  raise PathAlreadyExistsError.new(app) if fs.exist?(app)

  fs.mkdir(app)
  fs.chdir(app) do
    context = Generators::Context.new(inflector, app, head: head, skip_assets: skip_assets)
    generator.call(app, context: context) do
      if skip_install
        out.puts "Skipping installation, please enter `#{app}' directory and run `bundle exec hanami install'"
      else
        out.puts "Running Bundler install..."
        bundler.install!

        unless skip_assets
          out.puts "Running NPM install..."
          system_call.call("npm", ["install"]).tap do |result|
            unless result.successful?
              puts "NPM ERROR:"
              puts(result.err.lines.map { |line| line.prepend("    ") })
            end
          end
        end

        out.puts "Running Hanami install..."
        run_install_command!(head: head)
      end
    end
  end
end