Skip to content

Commit

Permalink
Replace spree:site with spree:install
Browse files Browse the repository at this point in the history
  • Loading branch information
LBRapid committed Nov 15, 2011
1 parent dd8556d commit f1dd0a1
Show file tree
Hide file tree
Showing 8 changed files with 155 additions and 143 deletions.
4 changes: 2 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -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|
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion core/lib/spree/core/testing_support/common_rake.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
144 changes: 144 additions & 0 deletions lib/generators/spree/install/install_generator.rb
Original file line number Diff line number Diff line change
@@ -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
148 changes: 8 additions & 140 deletions lib/generators/spree/site/site_generator.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit f1dd0a1

Please sign in to comment.