From f1dd0a1a6cfb23bac60f55d6b87635698bd6f39c Mon Sep 17 00:00:00 2001 From: John Dyer Date: Mon, 14 Nov 2011 14:08:50 -0500 Subject: [PATCH] Replace spree:site with spree:install --- Rakefile | 4 +- .../spree/core/testing_support/common_rake.rb | 2 +- .../spree/install/install_generator.rb | 144 +++++++++++++++++ .../app/assets/javascripts/admin/all.js | 0 .../app/assets/javascripts/store/all.js | 0 .../app/assets/stylesheets/admin/all.css | 0 .../app/assets/stylesheets/store/all.css | 0 lib/generators/spree/site/site_generator.rb | 148 +----------------- 8 files changed, 155 insertions(+), 143 deletions(-) create mode 100644 lib/generators/spree/install/install_generator.rb rename lib/generators/spree/{site => install}/templates/app/assets/javascripts/admin/all.js (100%) rename lib/generators/spree/{site => install}/templates/app/assets/javascripts/store/all.js (100%) rename lib/generators/spree/{site => install}/templates/app/assets/stylesheets/admin/all.css (100%) rename lib/generators/spree/{site => install}/templates/app/assets/stylesheets/store/all.css (100%) diff --git a/Rakefile b/Rakefile index 46986326548..a118abe9a09 100644 --- a/Rakefile +++ b/Rakefile @@ -1,7 +1,7 @@ require 'rake' require 'rubygems/package_task' require 'thor/group' -require 'lib/generators/spree/site/site_generator' +require 'lib/generators/spree/install/install_generator' spec = eval(File.read('spree.gemspec')) Gem::PackageTask.new(spec) do |pkg| @@ -96,7 +96,7 @@ task :sandbox do require 'spree_core' Spree::SandboxGenerator.start ["--lib_name=spree", "--database=#{ENV['DB_NAME']}"] - Spree::SiteGenerator.start ["--auto-accept", "--skip-install-data"] + Spree::InstallGenerator.start ["--auto-accept", "--skip-install-data"] cmd = "bundle exec rake db:bootstrap AUTO_ACCEPT=true"; puts cmd; system cmd cmd = "bundle exec rake assets:precompile:nondigest"; puts cmd; system cmd diff --git a/core/lib/spree/core/testing_support/common_rake.rb b/core/lib/spree/core/testing_support/common_rake.rb index 4371f0684a3..0a304d967b9 100644 --- a/core/lib/spree/core/testing_support/common_rake.rb +++ b/core/lib/spree/core/testing_support/common_rake.rb @@ -1,4 +1,4 @@ -require '../lib/generators/spree/site/site_generator' +require '../lib/generators/spree/install/install_generator' desc "Generates a dummy app for testing" namespace :common do diff --git a/lib/generators/spree/install/install_generator.rb b/lib/generators/spree/install/install_generator.rb new file mode 100644 index 00000000000..0d4b94ec5cb --- /dev/null +++ b/lib/generators/spree/install/install_generator.rb @@ -0,0 +1,144 @@ +require 'rails/generators' +require 'highline/import' + +module Spree + class InstallGenerator < Rails::Generators::Base + argument :after_bundle_only, :type => :string, :default => "false" + + class_option :auto_accept, :type => :boolean, :default => false, :aliases => '-A', :desc => "Answer yes to all prompts" + class_option :skip_install_data, :type => :boolean, :default => false + class_option :lib_name, :default => 'spree' + attr :lib_name + attr :auto_accept + attr :skip_install_data + attr :test_app + + def self.source_paths + paths = self.superclass.source_paths + paths << File.expand_path('../templates', "../../#{__FILE__}") + paths << File.expand_path('../templates', "../#{__FILE__}") + paths << File.expand_path('../templates', __FILE__) + paths.flatten + end + + def config_spree_yml + create_file "config/spree.yml" do + settings = { 'version' => Spree.version } + + settings.to_yaml + end + end + + def remove_unneeded_files + remove_file "public/index.html" + end + + def additional_tweaks + @lib_name = options[:lib_name] + + return unless File.exists? 'public/robots.txt' + append_file "public/robots.txt", <<-ROBOTS +User-agent: * +Disallow: /checkouts +Disallow: /orders +Disallow: /countries +Disallow: /line_items +Disallow: /password_resets +Disallow: /states +Disallow: /user_sessions +Disallow: /users + ROBOTS + end + + def setup_assets + remove_file "app/assets/javascripts/application.js" + remove_file "app/assets/stylesheets/application.css" + remove_file "app/assets/images/rails.png" + + %w{javascripts stylesheets images}.each do |path| + empty_directory "app/assets/#{path}/store" + empty_directory "app/assets/#{path}/admin" + end + + template "app/assets/javascripts/store/all.js" + template "app/assets/javascripts/admin/all.js" + template "app/assets/stylesheets/store/all.css" + template "app/assets/stylesheets/admin/all.css" + end + + def create_overrides_directory + empty_directory "app/overrides" + end + + def configure_application + application <<-APP + config.middleware.use "Spree::Core::Middleware::SeoAssist" + config.middleware.use "Spree::Core::Middleware::RedirectLegacyProductUrl" + + config.to_prepare do + #loads application's model / class decorators + Dir.glob(File.join(File.dirname(__FILE__), "../app/**/*_decorator*.rb")) do |c| + Rails.configuration.cache_classes ? require(c) : load(c) + end + end + APP + + append_file "config/environment.rb", "\nActiveRecord::Base.include_root_in_json = true\n" + end + + def include_seed_data + append_file "db/seeds.rb", <<-SEEDS +\n +Spree::Core::Engine.load_seed if defined?(Spree::Core) +Spree::Auth::Engine.load_seed if defined?(Spree::Auth) + SEEDS + end + + def install_migrations + silence_warnings { run 'bundle exec rake railties:install:migrations' } + end + + def run_migrations + unless options[:skip_install_data] + unless options[:auto_accept] + res = agree('Would you like to run migrations? (y/n)') + end + if res || options[:auto_accept] + puts "Running migrations" + rake('db:migrate') + else + @migrations_skipped = true + puts "Skipping rake db:migrate, don't forget to run it!" + end + end + end + + def populate_seed_data + unless options[:skip_install_data] + unless options[:auto_accept] || @migrations_skipped + res = agree('Would you like to load the seed data? (y/n)') + end + if res || options[:auto_accept] + puts "Loading seed data" + rake('db:seed AUTO_ACCEPT=true') + else + puts "Skipping rake db:seed." + end + end + end + + def load_sample_data + unless options[:skip_install_data] + unless options[:auto_accept] || @migrations_skipped + res = agree('Would you like to load sample data? (y/n)') + end + if res || options[:auto_accept] + puts "Loading sample data" + rake('spree_sample:load') + else + puts "Skipping loading sample data. You can always run this later with rake spree_sample:load." + end + end + end + end +end diff --git a/lib/generators/spree/site/templates/app/assets/javascripts/admin/all.js b/lib/generators/spree/install/templates/app/assets/javascripts/admin/all.js similarity index 100% rename from lib/generators/spree/site/templates/app/assets/javascripts/admin/all.js rename to lib/generators/spree/install/templates/app/assets/javascripts/admin/all.js diff --git a/lib/generators/spree/site/templates/app/assets/javascripts/store/all.js b/lib/generators/spree/install/templates/app/assets/javascripts/store/all.js similarity index 100% rename from lib/generators/spree/site/templates/app/assets/javascripts/store/all.js rename to lib/generators/spree/install/templates/app/assets/javascripts/store/all.js diff --git a/lib/generators/spree/site/templates/app/assets/stylesheets/admin/all.css b/lib/generators/spree/install/templates/app/assets/stylesheets/admin/all.css similarity index 100% rename from lib/generators/spree/site/templates/app/assets/stylesheets/admin/all.css rename to lib/generators/spree/install/templates/app/assets/stylesheets/admin/all.css diff --git a/lib/generators/spree/site/templates/app/assets/stylesheets/store/all.css b/lib/generators/spree/install/templates/app/assets/stylesheets/store/all.css similarity index 100% rename from lib/generators/spree/site/templates/app/assets/stylesheets/store/all.css rename to lib/generators/spree/install/templates/app/assets/stylesheets/store/all.css diff --git a/lib/generators/spree/site/site_generator.rb b/lib/generators/spree/site/site_generator.rb index 5b8c068bf38..5d712f8891d 100644 --- a/lib/generators/spree/site/site_generator.rb +++ b/lib/generators/spree/site/site_generator.rb @@ -1,151 +1,19 @@ require 'rails/generators' +require File.expand_path('../../install/install_generator', __FILE__) module Spree class SiteGenerator < Rails::Generators::Base - argument :after_bundle_only, :type => :string, :default => "false" - class_option :auto_accept, :type => :boolean, :default => false, :aliases => '-A', :desc => "Answer yes to all prompts" - class_option :skip_install_data, :type => :boolean, :default => false - class_option :lib_name, :default => 'spree' - attr :lib_name - attr :auto_accept - attr :skip_install_data - attr :test_app - - def self.source_paths - paths = self.superclass.source_paths - paths << File.expand_path('../templates', "../../#{__FILE__}") - paths << File.expand_path('../templates', "../#{__FILE__}") - paths << File.expand_path('../templates', __FILE__) - paths.flatten - end - - def config_spree_yml - create_file "config/spree.yml" do - settings = { 'version' => Spree.version } - - settings.to_yaml - end - end - - def remove_unneeded_files - remove_file "public/index.html" - end - - def additional_tweaks - @lib_name = options[:lib_name] - - return unless File.exists? 'public/robots.txt' - append_file "public/robots.txt", <<-ROBOTS -User-agent: * -Disallow: /checkouts -Disallow: /orders -Disallow: /countries -Disallow: /line_items -Disallow: /password_resets -Disallow: /states -Disallow: /user_sessions -Disallow: /users - ROBOTS - end - - def setup_assets - remove_file "app/assets/javascripts/application.js" - remove_file "app/assets/stylesheets/application.css" - remove_file "app/assets/images/rails.png" - - %w{javascripts stylesheets images}.each do |path| - empty_directory "app/assets/#{path}/store" - empty_directory "app/assets/#{path}/admin" - end - - template "app/assets/javascripts/store/all.js" - template "app/assets/javascripts/admin/all.js" - template "app/assets/stylesheets/store/all.css" - template "app/assets/stylesheets/admin/all.css" - end - def create_overrides_directory - empty_directory "app/overrides" - end - - def configure_application - application <<-APP - config.middleware.use "Spree::Core::Middleware::SeoAssist" - config.middleware.use "Spree::Core::Middleware::RedirectLegacyProductUrl" - - config.to_prepare do - #loads application's model / class decorators - Dir.glob(File.join(File.dirname(__FILE__), "../app/**/*_decorator*.rb")) do |c| - Rails.configuration.cache_classes ? require(c) : load(c) - end - end - APP - - append_file "config/environment.rb", "\nActiveRecord::Base.include_root_in_json = true\n" - end - - def include_seed_data - append_file "db/seeds.rb", <<-SEEDS -\n -Spree::Core::Engine.load_seed if defined?(Spree::Core) -Spree::Auth::Engine.load_seed if defined?(Spree::Auth) - SEEDS - end - - def install_migrations - puts "Copying migrations..." - cmd = 'bundle exec rake railties:install:migrations' - silence_stream(STDOUT) do - silence_warnings do - run cmd - end - end - end - - def run_migrations - unless options[:skip_install_data] - unless options[:auto_accept] - res = ask "Would you like to run migrations?" - end - if res.present? && res.downcase =~ /y[es]*/ || options[:auto_accept] - puts "Running migrations" - rake('db:migrate') - else - @migrations_skipped = true - puts "Skipping rake db:migrate, don't forget to run it!" - end - end - end - - def populate_seed_data - unless options[:skip_install_data] - unless options[:auto_accept] || @migrations_skipped - res = ask "Would you like to load the seed data?" - end - if options[:auto_accept] - puts "Loading seed data" - rake('db:seed AUTO_ACCEPT=true') - elsif res.present? && res.downcase =~ /y[es]*/ - puts "Loading seed data" - rake('db:seed') - else - puts "Skipping rake db:seed." - end - end + def deprecated + puts ActiveSupport::Deprecation.warn "rails g spree:site is deprecated and may be removed from future releases, use rails g spree:install instead." end - def load_sample_data - unless options[:skip_install_data] - unless options[:auto_accept] || @migrations_skipped - res = ask "Would you like to load the sample data?" - end - if res.present? && res.downcase =~ /y[es]*/ || options[:auto_accept] - puts "Loading sample data" - rake('spree_sample:load') - else - puts "Skipping loading sample data. You can always run this later with rake spree_sample:load." - end + def run_install_generator + if options[:auto_accept] + Spree::InstallGenerator.start ["--auto-accept"] + else + Spree::InstallGenerator.start end end end