-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4087 from nebulab/waiting-for-dev/update_task
Introduce Solidus update process
- Loading branch information
Showing
17 changed files
with
479 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
core/lib/generators/solidus/update/templates/config/initializers/new_solidus_defaults.rb.tt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# This initializer lets you preview the defaults that have changed on the new | ||
# Solidus version. | ||
# | ||
# It allows you to enable them one by one while you adapt your application. | ||
# When you're done with all of them, you can safely remove this file and add | ||
# the updated `load_defaults` calls to the top of the config blocks in your | ||
# Solidus main initializer. You can also call `Spree.load_defaults(version)` to | ||
# target all components at once. | ||
|
||
Spree.config do |config| | ||
<%= @core_changes %> | ||
end | ||
|
||
<% if defined?(Spree::Frontend::Engine) -%> | ||
Spree::Frontend::Config.configure do |config| | ||
<%= @frontend_changes %> | ||
end | ||
<% end -%> | ||
|
||
<% if defined?(Spree::Backend::Engine) -%> | ||
Spree::Backend::Config.configure do |config| | ||
<%= @backend_changes %> | ||
end | ||
<% end -%> | ||
|
||
<% if defined?(Spree::Api::Engine) -%> | ||
Spree::Api::Config.configure do |config| | ||
<%= @api_changes %> | ||
end | ||
<% end -%> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spree/preferences/preference_differentiator' | ||
require 'rails/generators' | ||
|
||
module Solidus | ||
# @private | ||
class UpdateGenerator < ::Rails::Generators::Base | ||
FROM = Spree.previous_solidus_minor_version | ||
|
||
desc 'Generates a new initializer to preview the new defaults for current Solidus version' | ||
|
||
source_root File.expand_path('templates', __dir__) | ||
|
||
class_option :initializer_basename, | ||
type: :string, | ||
default: 'new_solidus_defaults', | ||
banner: 'The name for the new initializer' | ||
|
||
class_option :previous_version_prompt, | ||
type: :boolean, | ||
default: true, | ||
banner: 'Prompt to warn about only previous version support' | ||
|
||
class_option :from, | ||
type: :string, | ||
default: FROM, | ||
banner: 'Solidus version from which you are upgrading' | ||
|
||
class_option :to, | ||
type: :string, | ||
default: Spree.solidus_version, | ||
hide: true | ||
|
||
class_option :initializer_directory, | ||
type: :string, | ||
default: 'config/initializers/', | ||
hide: true | ||
|
||
def create_new_defaults_initializer | ||
previous_version_prompt = options[:previous_version_prompt] | ||
return if previous_version_prompt && !yes?(<<~MSG, :red) | ||
The update process is only supported if you are coming from version #{FROM}. If this is not the case, please, skip it and update your application to use Solidus #{FROM} before retrying. | ||
If you are confident you want to upgrade from a previous version, you must rerun the generator with the "--from={OLD_VERSION}" argument. | ||
Are you sure you want to continue? (y/N) | ||
MSG | ||
|
||
from = options[:from] | ||
to = options[:to] | ||
@from = from | ||
@core_changes = core_changes_template(from, to) | ||
@frontend_changes = frontend_changes_template(from, to) | ||
@backend_changes = backend_changes_template(from, to) | ||
@api_changes = api_changes_template(from, to) | ||
|
||
template 'config/initializers/new_solidus_defaults.rb.tt', | ||
File.join(options[:initializer_directory], "#{options[:initializer_basename]}.rb") | ||
end | ||
|
||
private | ||
|
||
def core_changes_template(from, to) | ||
changes_template_for(Spree::AppConfiguration, from, to) | ||
end | ||
|
||
def frontend_changes_template(from, to) | ||
return '' unless defined?(Spree::Frontend::Engine) | ||
|
||
changes_template_for(Spree::FrontendConfiguration, from, to) | ||
end | ||
|
||
def backend_changes_template(from, to) | ||
return '' unless defined?(Spree::Backend::Engine) | ||
|
||
changes_template_for(Spree::BackendConfiguration, from, to) | ||
end | ||
|
||
def api_changes_template(from, to) | ||
return '' unless defined?(Spree::Api::Engine) | ||
|
||
changes_template_for(Spree::ApiConfiguration, from, to) | ||
end | ||
|
||
def changes_template_for(klass, from, to) | ||
changes = Spree::Preferences::PreferenceDifferentiator.new(klass).call(from: from, to: to) | ||
return '# No changes' if changes.empty? | ||
|
||
[ | ||
["config.load_defaults('#{from}')"] + | ||
changes.map do |pref_key, change| | ||
" # config.#{pref_key} = #{change[:to]}" | ||
end.flatten | ||
].join("\n") | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# frozen_string_literal: true | ||
|
||
module Spree | ||
module Preferences | ||
class PreferenceDifferentiator | ||
attr_reader :config_class | ||
|
||
def initialize(config_class) | ||
@config_class = config_class | ||
end | ||
|
||
def call(from:, to:) | ||
preferences_from = config_class.new.load_defaults(from) | ||
preferences_to = config_class.new.load_defaults(to) | ||
preferences_from.reduce({}) do |changes, (pref_key, value_from)| | ||
value_to = preferences_to[pref_key] | ||
if value_from == value_to | ||
changes | ||
else | ||
changes.merge( | ||
pref_key => { from: value_from, to: value_to } | ||
) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.