diff options
-rw-r--r-- | railties/lib/rails/generators/app_base.rb | 6 | ||||
-rw-r--r-- | railties/lib/rails/generators/rails/app/app_generator.rb | 3 | ||||
-rw-r--r-- | railties/test/generators/app_generator_test.rb | 14 |
3 files changed, 22 insertions, 1 deletions
diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb index 410e53b4c0..2e4797e5bb 100644 --- a/railties/lib/rails/generators/app_base.rb +++ b/railties/lib/rails/generators/app_base.rb @@ -399,6 +399,10 @@ module Rails !options[:skip_spring] && !options.dev? && Process.respond_to?(:fork) && !RUBY_PLATFORM.include?("cygwin") end + def webpack_install? + !(options[:skip_javascript] || options[:skip_webpack_install]) + end + def depends_on_system_test? !(options[:skip_system_test] || options[:skip_test] || options[:api]) end @@ -420,7 +424,7 @@ module Rails end def run_webpack - unless options[:skip_javascript] + if webpack_install? rails_command "webpacker:install" rails_command "webpacker:install:#{options[:webpack]}" if options[:webpack] && options[:webpack] != "webpack" end diff --git a/railties/lib/rails/generators/rails/app/app_generator.rb b/railties/lib/rails/generators/rails/app/app_generator.rb index cefaffcb20..b118ea989b 100644 --- a/railties/lib/rails/generators/rails/app/app_generator.rb +++ b/railties/lib/rails/generators/rails/app/app_generator.rb @@ -261,6 +261,9 @@ module Rails class_option :webpack, type: :string, default: nil, desc: "Preconfigure Webpack with a particular framework (options: #{WEBPACKS.join('/')})" + class_option :skip_webpack_install, type: :boolean, default: false, + desc: "Don't run Webpack install" + def initialize(*args) super diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index cd6bdd11c0..59fc2fcf96 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -825,6 +825,20 @@ class AppGeneratorTest < Rails::Generators::TestCase assert_gem "webpacker" end + def test_skip_webpack_install + command_check = -> command do + if command == "webpacker:install" + assert false, "webpacker:install expected not to be called." + end + end + + generator([destination_root], skip_webpack_install: true).stub(:rails_command, command_check) do + quietly { generator.invoke_all } + end + + assert_gem "webpacker" + end + def test_generator_if_skip_turbolinks_is_given run_generator [destination_root, "--skip-turbolinks", "--no-skip-javascript"] |