From e22bc1326debfc06dfda610fb0c53a917c91ff54 Mon Sep 17 00:00:00 2001 From: Sean Date: Fri, 25 Sep 2020 12:40:39 -0500 Subject: [PATCH] Fix the install generator ref #3775 Fixes the issues with the install generator by bundling after adding the extensions to the gemfile, stopping spring, and then running the install generators for each of the installed extensions. Currently this works a bit wonky as the extensions will ask if you want to run migrations, and that's not desirable as migrations are already run after these extensions are installed. Will fix and update shortly, just wanted to get this into a PR! --- .../solidus/install/install_generator.rb | 40 ++++++++++++++++--- 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/core/lib/generators/solidus/install/install_generator.rb b/core/lib/generators/solidus/install/install_generator.rb index ba0a4ab99aa..281f1d52f4c 100644 --- a/core/lib/generators/solidus/install/install_generator.rb +++ b/core/lib/generators/solidus/install/install_generator.rb @@ -111,14 +111,20 @@ def configure_application end end - def install_default_plugins + def plugin_install_preparation + @plugins_to_be_installed = [] + @plugin_generators_to_run = [] + end + + def install_auth_plugin if options[:with_authentication] && (options[:auto_accept] || !no?(" - Solidus has a default authentication extension that uses Devise. - You can find more info at https://github.com/solidusio/solidus_auth_devise. + Solidus has a default authentication extension that uses Devise. + You can find more info at https://github.com/solidusio/solidus_auth_devise. - Would you like to install it? (y/n)")) + Would you like to install it? (y/n)")) - gem 'solidus_auth_devise' + @plugins_to_be_installed << 'solidus_auth_devise' + @plugin_generators_to_run << 'solidus:auth:install' end end @@ -135,7 +141,10 @@ def install_payment_method gem_name = PAYMENT_METHODS.fetch(name) - gem gem_name if gem_name + if gem_name + @plugins_to_be_installed << gem_name + @plugin_generators_to_run << "#{gem_name}:install" + end end def include_seed_data @@ -156,6 +165,19 @@ def create_database rake 'db:create' end + def run_bundle_install_if_needed_by_plugins + @plugins_to_be_installed.each do |plugin_name| + gem plugin_name + end + + bundle_cleanly{ run "bundle install" } if @plugins_to_be_installed.any? + run "spring stop" + + @plugin_generators_to_run.each do |plugin_generator_name| + generate "#{plugin_generator_name} --skip_migrations=false" + end + end + def run_migrations if @run_migrations say_status :running, "migrations" @@ -221,5 +243,11 @@ def complete puts "Enjoy!" end end + + private + + def bundle_cleanly(&block) + Bundler.respond_to?(:with_unbundled_env) ? Bundler.with_unbundled_env(&block) : Bundler.with_clean_env(&block) + end end end