1
1
# frozen_string_literal: true
2
2
3
- require "rails/app_updater"
3
+ require "rails/generators"
4
+ require "rails/generators/rails/app/app_generator"
4
5
5
6
module Rails
6
7
module Command
@@ -11,27 +12,69 @@ def perform
11
12
configs
12
13
bin
13
14
active_storage
14
- Rails :: AppUpdater . invoke_from_app_generator : display_upgrade_guide_info
15
+ display_upgrade_guide_info
15
16
end
16
17
17
- desc "configs" , "Update configuration files in the application config/ directory" , hide : true
18
+ desc "configs" , "Update config files in the application config/ directory" , hide : true
18
19
def configs
19
20
require_application!
20
- Rails :: AppUpdater . invoke_from_app_generator : create_boot_file
21
- Rails :: AppUpdater . invoke_from_app_generator : update_config_files
21
+ app_generator . create_boot_file
22
+ app_generator . update_config_files
22
23
end
23
24
24
- desc "bin" , "Update executables in the application bin/ directory" , hide : true
25
+ desc "bin" , "Add or update executables in the application bin/ directory" , hide : true
25
26
def bin
26
27
require_application!
27
- Rails :: AppUpdater . invoke_from_app_generator : update_bin_files
28
+ app_generator . update_bin_files
28
29
end
29
30
30
31
desc "active_storage" , "Run the active_storage:update command" , hide : true
31
32
def active_storage
32
33
require_application!
33
- Rails :: AppUpdater . invoke_from_app_generator : update_active_storage
34
+ app_generator . update_active_storage
34
35
end
36
+
37
+ private
38
+ def display_upgrade_guide_info
39
+ say "\n After this, check Rails upgrade guide at https://guides.rubyonrails.org/upgrading_ruby_on_rails.html for more details about upgrading your app."
40
+ end
41
+
42
+ def app_generator
43
+ @app_generator ||= begin
44
+ gen = Rails ::Generators ::AppGenerator . new ( [ "rails" ] , generator_options , destination_root : Rails . root )
45
+ gen . send ( :valid_const? ) unless File . exist? ( Rails . root . join ( "config" , "application.rb" ) )
46
+ gen
47
+ end
48
+ end
49
+
50
+ def generator_options
51
+ options = { api : !!Rails . application . config . api_only , update : true }
52
+ options [ :name ] = Rails . application . class . name . chomp ( "::Application" ) . underscore
53
+ options [ :skip_active_job ] = !defined? ( ActiveJob ::Railtie )
54
+ options [ :skip_active_record ] = !defined? ( ActiveRecord ::Railtie )
55
+ options [ :skip_active_storage ] = !defined? ( ActiveStorage ::Engine )
56
+ options [ :skip_action_mailer ] = !defined? ( ActionMailer ::Railtie )
57
+ options [ :skip_action_mailbox ] = !defined? ( ActionMailbox ::Engine )
58
+ options [ :skip_action_text ] = !defined? ( ActionText ::Engine )
59
+ options [ :skip_action_cable ] = !defined? ( ActionCable ::Engine )
60
+ options [ :skip_test ] = !defined? ( Rails ::TestUnitRailtie )
61
+ options [ :skip_system_test ] = Rails . application . config . generators . system_tests . nil?
62
+ options [ :asset_pipeline ] = asset_pipeline
63
+ options [ :skip_asset_pipeline ] = asset_pipeline . nil?
64
+ options [ :skip_bootsnap ] = !defined? ( Bootsnap )
65
+ options
66
+ end
67
+
68
+ def asset_pipeline
69
+ case
70
+ when defined? ( Sprockets ::Railtie )
71
+ "sprockets"
72
+ when defined? ( Propshaft ::Railtie )
73
+ "propshaft"
74
+ else
75
+ nil
76
+ end
77
+ end
35
78
end
36
79
end
37
80
end
0 commit comments