mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #28557 from y-yagi/remove_unnecessary_files_to_api_applications_when_app_task_task_executed
Remove unnecessary files to API-only Applications when `app:task` task executed
This commit is contained in:
commit
f76881750d
3 changed files with 56 additions and 1 deletions
|
@ -84,6 +84,16 @@ module Rails
|
|||
chmod "bin", 0755 & ~File.umask, verbose: false
|
||||
end
|
||||
|
||||
def bin_when_updating
|
||||
bin_yarn_exist = File.exist?("bin/yarn")
|
||||
|
||||
bin
|
||||
|
||||
if options[:api] && !bin_yarn_exist
|
||||
remove_file "bin/yarn"
|
||||
end
|
||||
end
|
||||
|
||||
def config
|
||||
empty_directory "config"
|
||||
|
||||
|
@ -106,6 +116,8 @@ module Rails
|
|||
cookie_serializer_config_exist = File.exist?("config/initializers/cookies_serializer.rb")
|
||||
action_cable_config_exist = File.exist?("config/cable.yml")
|
||||
rack_cors_config_exist = File.exist?("config/initializers/cors.rb")
|
||||
assets_config_exist = File.exist?("config/initializers/assets.rb")
|
||||
new_framework_defaults_5_1_exist = File.exist?("config/initializers/new_framework_defaults_5_1.rb")
|
||||
|
||||
config
|
||||
|
||||
|
@ -120,6 +132,22 @@ module Rails
|
|||
unless rack_cors_config_exist
|
||||
remove_file "config/initializers/cors.rb"
|
||||
end
|
||||
|
||||
if options[:api]
|
||||
unless cookie_serializer_config_exist
|
||||
remove_file "config/initializers/cookies_serializer.rb"
|
||||
end
|
||||
|
||||
unless assets_config_exist
|
||||
remove_file "config/initializers/assets.rb"
|
||||
end
|
||||
|
||||
# Sprockets owns the only new default for 5.1:
|
||||
# In API-only Applications, we don't want the file.
|
||||
unless new_framework_defaults_5_1_exist
|
||||
remove_file "config/initializers/new_framework_defaults_5_1.rb"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def database_yml
|
||||
|
@ -230,6 +258,11 @@ module Rails
|
|||
build(:bin)
|
||||
end
|
||||
|
||||
def update_bin_files
|
||||
build(:bin_when_updating)
|
||||
end
|
||||
remove_task :update_bin_files
|
||||
|
||||
def create_config_files
|
||||
build(:config)
|
||||
end
|
||||
|
|
|
@ -63,7 +63,7 @@ namespace :app do
|
|||
|
||||
# desc "Adds new executables to the application bin/ directory"
|
||||
task :bin do
|
||||
RailsUpdate.invoke_from_app_generator :create_bin_files
|
||||
RailsUpdate.invoke_from_app_generator :update_bin_files
|
||||
end
|
||||
|
||||
task :upgrade_guide_info do
|
||||
|
|
|
@ -61,6 +61,28 @@ class ApiAppGeneratorTest < Rails::Generators::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
def test_app_update_does_not_generate_unnecessary_config_files
|
||||
run_generator
|
||||
|
||||
generator = Rails::Generators::AppGenerator.new ["rails"],
|
||||
{ api: true, update: true }, destination_root: destination_root, shell: @shell
|
||||
quietly { generator.send(:update_config_files) }
|
||||
|
||||
assert_no_file "config/initializers/cookies_serializer.rb"
|
||||
assert_no_file "config/initializers/assets.rb"
|
||||
assert_no_file "config/initializers/new_framework_defaults_5_1.rb"
|
||||
end
|
||||
|
||||
def test_app_update_does_not_generate_unnecessary_bin_files
|
||||
run_generator
|
||||
|
||||
generator = Rails::Generators::AppGenerator.new ["rails"],
|
||||
{ api: true, update: true }, destination_root: destination_root, shell: @shell
|
||||
quietly { generator.send(:update_bin_files) }
|
||||
|
||||
assert_no_file "bin/yarn"
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def default_files
|
||||
|
|
Loading…
Reference in a new issue