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

Constant Summary collapse

DATABASE_SQLITE =

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

Since:

  • 2.2.0

"sqlite"
DATABASE_POSTGRES =

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

Since:

  • 2.2.0

"postgres"
DATABASE_MYSQL =

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

Since:

  • 2.2.0

"mysql"
SUPPORTED_DATABASES =

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

Since:

  • 2.2.0

[DATABASE_SQLITE, DATABASE_POSTGRES, DATABASE_MYSQL].freeze
FORBIDDEN_APP_NAMES =

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

Since:

  • 2.0.0

%w[app slice].freeze

Instance Method Summary collapse

Methods inherited from Hanami::CLI::Command

#inflector, new

Constructor Details

#initialize(fs:, 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



127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/hanami/cli/commands/gem/new.rb', line 127

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

Instance Method Details

#call(app:, head: HEAD_DEFAULT, gem_source: GEM_SOURCE_DEFAULT, skip_install: SKIP_INSTALL_DEFAULT, skip_assets: SKIP_ASSETS_DEFAULT, skip_db: SKIP_DB_DEFAULT, skip_view: SKIP_VIEW_DEFAULT, database: nil) ⇒ 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



144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# File 'lib/hanami/cli/commands/gem/new.rb', line 144

def call(
  app:,
  head: HEAD_DEFAULT,
  gem_source: GEM_SOURCE_DEFAULT,
  skip_install: SKIP_INSTALL_DEFAULT,
  skip_assets: SKIP_ASSETS_DEFAULT,
  skip_db: SKIP_DB_DEFAULT,
  skip_view: SKIP_VIEW_DEFAULT,
  database: nil
)
  # rubocop:enable Metrics/ParameterLists
  app = inflector.underscore(app)

  raise PathAlreadyExistsError.new(app) if fs.exist?(app)
  raise ForbiddenAppNameError.new(app) if FORBIDDEN_APP_NAMES.include?(app)

  normalized_database ||= normalize_database(database)

  fs.mkdir(app)
  fs.chdir(app) do
    context = Generators::Context.new(
      inflector,
      app,
      head: head,
      gem_source: gem_source,
      skip_assets: skip_assets,
      skip_db: skip_db,
      skip_view: skip_view,
      database: normalized_database
    )
    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 bundle 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)

        out.puts "Running bundle binstubs hanami-cli rake..."
        install_binstubs!

        out.puts "Initializing git repository..."
        init_git_repository
      end
    end
  end
end