diff --git a/README.md b/README.md index 03cc9d05e99..27e32ff86f0 100644 --- a/README.md +++ b/README.md @@ -114,7 +114,7 @@ After installing gems, you'll have to run the generators to create necessary configuration files and migrations. ```bash -bundle exec rails g spree:install +bundle exec rails g solidus:install bundle exec rails g solidus:auth:install bundle exec rake railties:install:migrations ``` @@ -156,11 +156,11 @@ gem 'solidus', github: 'solidusio/solidus' **Note: The master branch is not guaranteed to ever be in a fully functioning state. It is too risky to use this branch in production.** -By default, the installation generator (`rails g spree:install`) will run +By default, the installation generator (`rails g solidus:install`) will run migrations as well as adding seed and sample data. This can be disabled using ```bash -rails g spree:install --migrate=false --sample=false --seed=false +rails g solidus:install --migrate=false --sample=false --seed=false ``` You can always perform any of these steps later by using these commands. diff --git a/bin/rails-application-template b/bin/rails-application-template index a7c540f9bfc..bd8a8c16c72 100755 --- a/bin/rails-application-template +++ b/bin/rails-application-template @@ -118,7 +118,7 @@ RUBY after_bundle do generate( - "spree:install", + "solidus:install", "--auto-accept", "--user_class=Spree::User", "--enforce_available_locales=true", diff --git a/bin/sandbox b/bin/sandbox index 1b12896e096..808ff585325 100755 --- a/bin/sandbox +++ b/bin/sandbox @@ -61,7 +61,7 @@ RUBY unbundled bundle install --gemfile Gemfile unbundled bin/rails db:drop db:create -unbundled bin/rails generate spree:install \ +unbundled bin/rails generate solidus:install \ --auto-accept \ --user_class=Spree::User \ --enforce_available_locales=true \ diff --git a/core/lib/generators/solidus/install/install_generator.rb b/core/lib/generators/solidus/install/install_generator.rb new file mode 100644 index 00000000000..26701f1f161 --- /dev/null +++ b/core/lib/generators/solidus/install/install_generator.rb @@ -0,0 +1,198 @@ +# frozen_string_literal: true + +require 'rails/generators' +require 'bundler' +require 'bundler/cli' + +module Solidus + # @private + 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)' + class_option :auto_accept, type: :boolean + class_option :user_class, type: :string + class_option :admin_email, type: :string + class_option :admin_password, type: :string + class_option :lib_name, type: :string, default: 'spree' + class_option :enforce_available_locales, type: :boolean, default: nil + + def self.source_paths + paths = superclass.source_paths + paths << File.expand_path('../templates', "../../#{__FILE__}") + paths << File.expand_path('../templates', "../#{__FILE__}") + paths << File.expand_path('templates', __dir__) + paths.flatten + end + + def prepare_options + @run_migrations = options[:migrate] + @load_seed_data = options[:seed] + @load_sample_data = options[:sample] + + unless @run_migrations + @load_seed_data = false + @load_sample_data = false + end + end + + def add_files + template 'config/initializers/spree.rb.tt', 'config/initializers/spree.rb' + end + + def additional_tweaks + return unless File.exist? 'public/robots.txt' + + append_file "public/robots.txt", <<-ROBOTS.strip_heredoc + User-agent: * + Disallow: /checkout + Disallow: /cart + Disallow: /orders + Disallow: /user + Disallow: /account + Disallow: /api + Disallow: /password + ROBOTS + end + + def setup_assets + @lib_name = 'spree' + + empty_directory 'app/assets/images' + + %w{javascripts stylesheets images}.each do |path| + empty_directory "vendor/assets/#{path}/spree/frontend" if defined? Spree::Frontend || Rails.env.test? + empty_directory "vendor/assets/#{path}/spree/backend" if defined? Spree::Backend || Rails.env.test? + end + + if defined? Spree::Frontend || Rails.env.test? + template "vendor/assets/javascripts/spree/frontend/all.js" + template "vendor/assets/stylesheets/spree/frontend/all.css" + end + + if defined? Spree::Backend || Rails.env.test? + template "vendor/assets/javascripts/spree/backend/all.js" + template "vendor/assets/stylesheets/spree/backend/all.css" + end + end + + def create_overrides_directory + empty_directory "app/overrides" + end + + def configure_application + application <<-RUBY + # Load application's model / class decorators + initializer 'spree.decorators' do |app| + config.to_prepare do + Dir.glob(Rails.root.join('app/**/*_decorator*.rb')) do |path| + require_dependency(path) + end + end + end + + # Load application's view overrides + initializer 'spree.overrides' do |app| + config.to_prepare do + Dir.glob(Rails.root.join('app/overrides/*.rb')) do |path| + require_dependency(path) + end + end + end + RUBY + + if !options[:enforce_available_locales].nil? + application <<-RUBY + # Prevent this deprecation message: https://github.com/svenfuchs/i18n/commit/3b6e56e + I18n.enforce_available_locales = #{options[:enforce_available_locales]} + RUBY + end + end + + def include_seed_data + append_file "db/seeds.rb", <<-RUBY.strip_heredoc + + Spree::Core::Engine.load_seed if defined?(Spree::Core) + Spree::Auth::Engine.load_seed if defined?(Spree::Auth) + RUBY + end + + def install_migrations + say_status :copying, "migrations" + `rake railties:install:migrations` + end + + def create_database + say_status :creating, "database" + rake 'db:create' + end + + def run_migrations + if @run_migrations + say_status :running, "migrations" + + rake 'db:migrate VERBOSE=false' + else + say_status :skipping, "migrations (don't forget to run rake db:migrate)" + end + end + + def populate_seed_data + if @load_seed_data + say_status :loading, "seed data" + rake_options = [] + rake_options << "AUTO_ACCEPT=1" if options[:auto_accept] + rake_options << "ADMIN_EMAIL=#{options[:admin_email]}" if options[:admin_email] + rake_options << "ADMIN_PASSWORD=#{options[:admin_password]}" if options[:admin_password] + + rake("db:seed #{rake_options.join(' ')}") + else + say_status :skipping, "seed data (you can always run rake db:seed)" + end + end + + def load_sample_data + if @load_sample_data + say_status :loading, "sample data" + rake 'spree_sample:load' + else + say_status :skipping, "sample data (you can always run rake spree_sample:load)" + end + end + + def install_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 + <<-RUBY + # 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" + #{CORE_MOUNT_ROUTE}, at: '/' + + RUBY + end + end + + unless options[:quiet] + puts "*" * 50 + puts "We added the following line to your application's config/routes.rb file:" + puts " " + puts " #{CORE_MOUNT_ROUTE}, at: '/'" + end + end + + def complete + unless options[:quiet] + puts "*" * 50 + puts "Solidus has been installed successfully. You're all ready to go!" + puts " " + puts "Enjoy!" + end + end + end +end diff --git a/core/lib/generators/spree/install/templates/config/initializers/spree.rb.tt b/core/lib/generators/solidus/install/templates/config/initializers/spree.rb.tt similarity index 100% rename from core/lib/generators/spree/install/templates/config/initializers/spree.rb.tt rename to core/lib/generators/solidus/install/templates/config/initializers/spree.rb.tt diff --git a/core/lib/generators/spree/install/templates/vendor/assets/javascripts/spree/backend/all.js b/core/lib/generators/solidus/install/templates/vendor/assets/javascripts/spree/backend/all.js similarity index 100% rename from core/lib/generators/spree/install/templates/vendor/assets/javascripts/spree/backend/all.js rename to core/lib/generators/solidus/install/templates/vendor/assets/javascripts/spree/backend/all.js diff --git a/core/lib/generators/spree/install/templates/vendor/assets/javascripts/spree/frontend/all.js b/core/lib/generators/solidus/install/templates/vendor/assets/javascripts/spree/frontend/all.js similarity index 100% rename from core/lib/generators/spree/install/templates/vendor/assets/javascripts/spree/frontend/all.js rename to core/lib/generators/solidus/install/templates/vendor/assets/javascripts/spree/frontend/all.js diff --git a/core/lib/generators/spree/install/templates/vendor/assets/stylesheets/spree/backend/all.css b/core/lib/generators/solidus/install/templates/vendor/assets/stylesheets/spree/backend/all.css similarity index 100% rename from core/lib/generators/spree/install/templates/vendor/assets/stylesheets/spree/backend/all.css rename to core/lib/generators/solidus/install/templates/vendor/assets/stylesheets/spree/backend/all.css diff --git a/core/lib/generators/spree/install/templates/vendor/assets/stylesheets/spree/frontend/all.css b/core/lib/generators/solidus/install/templates/vendor/assets/stylesheets/spree/frontend/all.css similarity index 100% rename from core/lib/generators/spree/install/templates/vendor/assets/stylesheets/spree/frontend/all.css rename to core/lib/generators/solidus/install/templates/vendor/assets/stylesheets/spree/frontend/all.css diff --git a/core/lib/generators/spree/install/install_generator.rb b/core/lib/generators/spree/install/install_generator.rb index 21975b5f05d..f65d23f4079 100644 --- a/core/lib/generators/spree/install/install_generator.rb +++ b/core/lib/generators/spree/install/install_generator.rb @@ -1,197 +1,15 @@ # frozen_string_literal: true -require 'rails/generators' -require 'bundler' -require 'bundler/cli' +require 'generators/solidus/install/install_generator' module Spree # @private - 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)' - class_option :auto_accept, type: :boolean - class_option :user_class, type: :string - class_option :admin_email, type: :string - class_option :admin_password, type: :string - class_option :lib_name, type: :string, default: 'spree' - class_option :enforce_available_locales, type: :boolean, default: nil - - def self.source_paths - paths = superclass.source_paths - paths << File.expand_path('../templates', "../../#{__FILE__}") - paths << File.expand_path('../templates', "../#{__FILE__}") - paths << File.expand_path('templates', __dir__) - paths.flatten - end - - def prepare_options - @run_migrations = options[:migrate] - @load_seed_data = options[:seed] - @load_sample_data = options[:sample] - - unless @run_migrations - @load_seed_data = false - @load_sample_data = false - end - end - - def add_files - template 'config/initializers/spree.rb.tt', 'config/initializers/spree.rb' - end - - def additional_tweaks - return unless File.exist? 'public/robots.txt' - append_file "public/robots.txt", <<-ROBOTS.strip_heredoc - User-agent: * - Disallow: /checkout - Disallow: /cart - Disallow: /orders - Disallow: /user - Disallow: /account - Disallow: /api - Disallow: /password - ROBOTS - end - - def setup_assets - @lib_name = 'spree' - - empty_directory 'app/assets/images' - - %w{javascripts stylesheets images}.each do |path| - empty_directory "vendor/assets/#{path}/spree/frontend" if defined? Spree::Frontend || Rails.env.test? - empty_directory "vendor/assets/#{path}/spree/backend" if defined? Spree::Backend || Rails.env.test? - end - - if defined? Spree::Frontend || Rails.env.test? - template "vendor/assets/javascripts/spree/frontend/all.js" - template "vendor/assets/stylesheets/spree/frontend/all.css" - end - - if defined? Spree::Backend || Rails.env.test? - template "vendor/assets/javascripts/spree/backend/all.js" - template "vendor/assets/stylesheets/spree/backend/all.css" - end - end - - def create_overrides_directory - empty_directory "app/overrides" - end - - def configure_application - application <<-RUBY - # Load application's model / class decorators - initializer 'spree.decorators' do |app| - config.to_prepare do - Dir.glob(Rails.root.join('app/**/*_decorator*.rb')) do |path| - require_dependency(path) - end - end - end - - # Load application's view overrides - initializer 'spree.overrides' do |app| - config.to_prepare do - Dir.glob(Rails.root.join('app/overrides/*.rb')) do |path| - require_dependency(path) - end - end - end - RUBY - - if !options[:enforce_available_locales].nil? - application <<-RUBY - # Prevent this deprecation message: https://github.com/svenfuchs/i18n/commit/3b6e56e - I18n.enforce_available_locales = #{options[:enforce_available_locales]} - RUBY - end - end - - def include_seed_data - append_file "db/seeds.rb", <<-RUBY.strip_heredoc - - Spree::Core::Engine.load_seed if defined?(Spree::Core) - Spree::Auth::Engine.load_seed if defined?(Spree::Auth) - RUBY - end - - def install_migrations - say_status :copying, "migrations" - `rake railties:install:migrations` - end - - def create_database - say_status :creating, "database" - rake 'db:create' - end - - def run_migrations - if @run_migrations - say_status :running, "migrations" - - rake 'db:migrate VERBOSE=false' - else - say_status :skipping, "migrations (don't forget to run rake db:migrate)" - end - end - - def populate_seed_data - if @load_seed_data - say_status :loading, "seed data" - rake_options = [] - rake_options << "AUTO_ACCEPT=1" if options[:auto_accept] - rake_options << "ADMIN_EMAIL=#{options[:admin_email]}" if options[:admin_email] - rake_options << "ADMIN_PASSWORD=#{options[:admin_password]}" if options[:admin_password] - - rake("db:seed #{rake_options.join(' ')}") - else - say_status :skipping, "seed data (you can always run rake db:seed)" - end - end - - def load_sample_data - if @load_sample_data - say_status :loading, "sample data" - rake 'spree_sample:load' - else - say_status :skipping, "sample data (you can always run rake spree_sample:load)" - end - end - - def install_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 - <<-RUBY - # 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" - #{CORE_MOUNT_ROUTE}, at: '/' - - RUBY - end - end - - unless options[:quiet] - puts "*" * 50 - puts "We added the following line to your application's config/routes.rb file:" - puts " " - puts " #{CORE_MOUNT_ROUTE}, at: '/'" - end - end - - def complete - unless options[:quiet] - puts "*" * 50 - puts "Solidus has been installed successfully. You're all ready to go!" - puts " " - puts "Enjoy!" - end + class InstallGenerator < Solidus::InstallGenerator + def print_deprecation_warning + puts " " + puts "*" * 50 + puts "spree:install generator is deprecated, please use solidus:install." + puts " " end end end diff --git a/core/lib/spree/testing_support/common_rake.rb b/core/lib/spree/testing_support/common_rake.rb index d3b498fae42..c2e42c9f995 100644 --- a/core/lib/spree/testing_support/common_rake.rb +++ b/core/lib/spree/testing_support/common_rake.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -unless defined?(Spree::InstallGenerator) - require 'generators/spree/install/install_generator' +unless defined?(Solidus::InstallGenerator) + require 'generators/solidus/install/install_generator' end require 'generators/spree/dummy/dummy_generator' @@ -14,7 +14,7 @@ ENV["RAILS_ENV"] = 'test' Spree::DummyGenerator.start ["--lib_name=#{ENV['LIB_NAME']}", "--quiet"] - Spree::InstallGenerator.start ["--lib_name=#{ENV['LIB_NAME']}", "--auto-accept", "--migrate=false", "--seed=false", "--sample=false", "--quiet", "--user_class=#{args[:user_class]}"] + Solidus::InstallGenerator.start ["--lib_name=#{ENV['LIB_NAME']}", "--auto-accept", "--migrate=false", "--seed=false", "--sample=false", "--quiet", "--user_class=#{args[:user_class]}"] puts "Setting up dummy database..." diff --git a/guides/source/developers/getting-started/first-time-installation.html.md b/guides/source/developers/getting-started/first-time-installation.html.md index a8e06ab523f..7e47ffe01a4 100644 --- a/guides/source/developers/getting-started/first-time-installation.html.md +++ b/guides/source/developers/getting-started/first-time-installation.html.md @@ -204,17 +204,17 @@ After the gems have been successfully installed, you need to create the necessary configuration files and instructions for the database using generators provided by Solidus and Railties. -First, run the `spree:install` generator: +First, run the `solidus:install` generator: ```bash -bundle exec rails generate spree:install +bundle exec rails generate solidus:install ``` This may take a few minutes to complete, and it requires some user confirmation. ### Set the administrator username and password -The `spree:install` generator prompts you to configure the Solidus administrator +The `solidus:install` generator prompts you to configure the Solidus administrator username and password values. The default values are as follows: diff --git a/guides/source/developers/getting-started/installation-options.html.md b/guides/source/developers/getting-started/installation-options.html.md index 936e6a48963..5bb1c0de780 100644 --- a/guides/source/developers/getting-started/installation-options.html.md +++ b/guides/source/developers/getting-started/installation-options.html.md @@ -11,29 +11,29 @@ gem 'solidus' ## Bleeding edge Solidus -If you want to use the bleeding edge version of Solidus, you can require the -Solidus GitHub repo's master branch: +If you want to use the bleeding edge version of Solidus, you can require the +Solidus GitHub repo's master branch: ```ruby gem 'solidus', github: 'solidusio/solidus' ``` The master branch is updated frequently and may break. Do not use this branch on -a production system. +a production system. -## Manually run migrations +## Manually run migrations -When you run the `spree:install` generator without arguments, it runs +When you run the `solidus:install` generator without arguments, it runs migrations, adds sample data, and seeds your database: ```bash -rails generate spree:install +rails generate solidus:install ``` You can use command arguments to skip any of these steps of the generator: ```bash -rails generate spree:install --migrate=false --sample=false --seed=false +rails generate solidus:install --migrate=false --sample=false --seed=false ``` If you want to perform these tasks later, you can use these commands.