Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore --payment-method= for solidus:install on v3.2 #4673

Merged
merged 6 commits into from
Oct 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 2 additions & 16 deletions bin/sandbox
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,8 @@ fi

cd ./sandbox
cat <<RUBY >> Gemfile

gem 'solidus', path: '..'
gem 'solidus_auth_devise', '>= 2.1.0'
gem 'rails-i18n'
gem 'solidus_i18n'

group :test, :development do
platforms :mri do
gem 'pry-byebug'
end
end
gem 'pry-byebug', group: [:test, :development], platforms: :mri
RUBY

replace_in_database_yml() {
Expand All @@ -88,12 +79,7 @@ fi

unbundled bundle install --gemfile Gemfile
unbundled bin/rails db:drop db:create
unbundled bin/rails generate solidus:install \
--auto-accept \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not super happy removing auto-accept by default, as it slows the development feedback. What do you think about keeping it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's no big deal either way, easy to add or remove locally as needed, so I'll add it back (I had to remove it in order to test out the interactive solidus:install wizard).

--user_class=Spree::User \
--enforce_available_locales=true \
--with_authentication=false
$@
unbundled bin/rails generate solidus:install --auto-accept $@

unbundled bin/rails generate solidus:auth:install \
--auto_run_migrations=true
Expand Down
63 changes: 48 additions & 15 deletions core/lib/generators/solidus/install/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ class InstallGenerator < Rails::Generators::Base
'none'
].freeze

PAYMENT_METHODS = {
'paypal' => 'solidus_paypal_commerce_platform',
'bolt' => 'solidus_bolt',
'none' => nil,
}

class_option :migrate, type: :boolean, default: true, banner: 'Run Solidus migrations'
class_option :seed, type: :boolean, default: true, banner: 'Load seed data (migrations must be run)'
class_option :sample, type: :boolean, default: true, banner: 'Load sample data (migrations must be run)'
Expand All @@ -28,13 +34,18 @@ class InstallGenerator < Rails::Generators::Base
class_option :admin_email, type: :string
class_option :admin_password, type: :string
class_option :lib_name, type: :string, default: 'spree'
class_option :with_authentication, type: :boolean, default: true
class_option :with_authentication, type: :boolean, default: nil
class_option :enforce_available_locales, type: :boolean, default: nil
class_option :frontend,
type: :string,
enum: FRONTENDS,
default: nil,
desc: "Indicates which frontend to install."
class_option :payment_method,
type: :string,
enum: PAYMENT_METHODS.keys,
default: nil,
desc: "Indicates which payment method to install."

def self.source_paths
paths = superclass.source_paths
Expand Down Expand Up @@ -118,7 +129,8 @@ def plugin_install_preparation
end

def install_auth_plugin
if options[:with_authentication] && (options[:auto_accept] || !no?("
with_authentication = options[:with_authentication]
with_authentication.nil? and 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.

Expand All @@ -127,11 +139,32 @@ def install_auth_plugin

Would you like to install it? (Y/n)"))

if with_authentication
@plugins_to_be_installed << 'solidus_auth_devise'
@plugin_generators_to_run << 'solidus:auth:install'
end
end

def install_payment_method
say_status :warning, set_color(
"Selecting a payment along with `solidus_starter_frontend` that might require manual integration.",
:yellow
), :yellow

name = options[:payment_method]
name ||= PAYMENT_METHODS.keys.first if options[:auto_accept]
name ||= ask("
You can select a payment method to be included in the installation process.
Please select a payment method name:", limited_to: PAYMENT_METHODS.keys, default: PAYMENT_METHODS.keys.first)

gem_name = PAYMENT_METHODS.fetch(name)

if gem_name
@plugins_to_be_installed << gem_name
@plugin_generators_to_run << "#{gem_name}:install"
end
end

def include_seed_data
append_file "db/seeds.rb", <<-RUBY.strip_heredoc

Expand All @@ -150,19 +183,6 @@ 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

BundlerContext.bundle_cleanly { run "bundle install" } if @plugins_to_be_installed.any?
run "spring stop" if defined?(Spring)

@plugin_generators_to_run.each do |plugin_generator_name|
generate "#{plugin_generator_name} --skip_migrations=true"
end
end

def install_frontend
return if options[:frontend] == 'none'

Expand All @@ -179,6 +199,19 @@ def install_frontend
call(frontend, installer_adds_auth: @plugins_to_be_installed.include?('solidus_auth_devise'))
end

def run_bundle_install_if_needed_by_plugins
@plugins_to_be_installed.each do |plugin_name|
gem plugin_name
end

BundlerContext.bundle_cleanly { run "bundle install" } if @plugins_to_be_installed.any?
run "spring stop" if defined?(Spring)

@plugin_generators_to_run.each do |plugin_generator_name|
generate "#{plugin_generator_name} --skip_migrations=true"
end
end

def run_migrations
if @run_migrations
say_status :running, "migrations"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,14 @@ def install_solidus_frontend
end
end

@generator_context.generate("solidus_frontend:install #{@generator_context.options[:auto_accept] ? '--auto-accept' : ''}")
# Solidus bolt will be handled in the installer as a payment method.
begin
skip_solidus_bolt = ENV['SKIP_SOLIDUS_BOLT']
ENV['SKIP_SOLIDUS_BOLT'] = 'true'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we move it here, I think we should remove the option from solidus_frontend altogether. Otherwise we're dealing with unneeded complexity here. WDYT?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 exactly, that's the idea, we can remove it as soon as v3.2 is updated

@generator_context.generate("solidus_frontend:install #{@generator_context.options[:auto_accept] ? '--auto-accept' : ''}")
ensure
ENV['SKIP_SOLIDUS_BOLT'] = skip_solidus_bolt
end
end

def install_solidus_starter_frontend(installer_adds_auth)
Expand Down