2017-08-14 13:08:09 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-06-25 16:46:12 -04:00
|
|
|
require "rails/generators"
|
|
|
|
require "rails/generators/rails/app/app_generator"
|
|
|
|
|
|
|
|
module Rails
|
|
|
|
class AppUpdater # :nodoc:
|
|
|
|
class << self
|
|
|
|
def invoke_from_app_generator(method)
|
|
|
|
app_generator.send(method)
|
|
|
|
end
|
|
|
|
|
|
|
|
def app_generator
|
|
|
|
@app_generator ||= begin
|
|
|
|
gen = Rails::Generators::AppGenerator.new ["rails"], generator_options, destination_root: Rails.root
|
|
|
|
File.exist?(Rails.root.join("config", "application.rb")) ? gen.send(:app_const) : gen.send(:valid_const?)
|
|
|
|
gen
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
def generator_options
|
|
|
|
options = { api: !!Rails.application.config.api_only, update: true }
|
2018-10-21 16:08:43 -04:00
|
|
|
options[:skip_javascript] = !File.exist?(Rails.root.join("bin", "yarn"))
|
2017-08-06 16:41:31 -04:00
|
|
|
options[:skip_active_record] = !defined?(ActiveRecord::Railtie)
|
|
|
|
options[:skip_active_storage] = !defined?(ActiveStorage::Engine) || !defined?(ActiveRecord::Railtie)
|
|
|
|
options[:skip_action_mailer] = !defined?(ActionMailer::Railtie)
|
|
|
|
options[:skip_action_cable] = !defined?(ActionCable::Engine)
|
|
|
|
options[:skip_sprockets] = !defined?(Sprockets::Railtie)
|
|
|
|
options[:skip_puma] = !defined?(Puma)
|
2018-05-06 18:56:00 -04:00
|
|
|
options[:skip_bootsnap] = !defined?(Bootsnap)
|
2018-05-07 04:25:01 -04:00
|
|
|
options[:skip_spring] = !defined?(Spring)
|
2017-06-25 16:46:12 -04:00
|
|
|
options
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|