-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
install_generator.rb
147 lines (127 loc) 路 4.19 KB
/
install_generator.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
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 create_overrides_directory
empty_directory "app/overrides"
end
def configure_application
application <<-APP
config.to_prepare do
# Load 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
# Load application's view overrides
Dir.glob(File.join(File.dirname(__FILE__), "../app/overrides/*.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..."
silence_stream(STDOUT) do
silence_warnings { run 'bundle exec rake railties:install:migrations' }
end
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
def notify_about_routes
insert_into_file File.join('config', 'routes.rb'), :after => "Application.routes.draw do\n" do
" # Mount Spree's routes\n mount Spree::Core::Engine, :at => '/'\n"
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 => '/'"
end
end
end
end