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

Make the install generator idempotent #2472

Merged
merged 1 commit into from
Jan 2, 2018
Merged
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
15 changes: 10 additions & 5 deletions core/lib/generators/spree/install/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

module Spree
class InstallGenerator < Rails::Generators::Base
CORE_MOUNT_ROUTE = "mount Spree::Core::Engine"

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 Down Expand Up @@ -149,23 +151,26 @@ def load_sample_data
end

def install_routes
insert_into_file File.join('config', 'routes.rb'), after: "Rails.application.routes.draw do\n" do
<<-ROUTES
routes_file_path = File.join('config', 'routes.rb')
unless File.read(routes_file_path).include? CORE_MOUNT_ROUTE
insert_into_file routes_file_path, after: "Rails.application.routes.draw do\n" do
<<-ROUTES
# This line mounts Solidus's routes at the root of your application.
# This means, any requests to URLs such as /products, will go to Spree::ProductsController.
# If you would like to change where this engine is mounted, simply change the :at option to something different.
#
# We ask that you don't use the :as option here, as Solidus relies on it being the default of "spree"
mount Spree::Core::Engine, at: '/'
#{CORE_MOUNT_ROUTE}, at: '/'

ROUTES
ROUTES
end
end

unless options[:quiet]
puts "*" * 50
puts "We added the following line to your application's config/routes.rb file:"
puts " "
puts " mount Spree::Core::Engine, at: '/'"
puts " #{CORE_MOUNT_ROUTE}, at: '/'"
end
end

Expand Down