Class: Solidus::InstallGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Solidus::InstallGenerator
show all
- Defined in:
- lib/generators/solidus/install/install_generator.rb,
lib/generators/solidus/install/install_generator/bundler_context.rb,
lib/generators/solidus/install/install_generator/install_frontend.rb,
lib/generators/solidus/install/install_generator/support_solidus_frontend_extraction.rb
Defined Under Namespace
Classes: BundlerContext, InstallFrontend, SupportSolidusFrontendExtraction
Constant Summary
collapse
- CORE_MOUNT_ROUTE =
"mount Spree::Core::Engine"
- LEGACY_FRONTEND =
'solidus_frontend'
- DEFAULT_FRONTEND =
'solidus_starter_frontend'
- FRONTENDS =
[
DEFAULT_FRONTEND,
LEGACY_FRONTEND,
'none'
].freeze
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.source_paths ⇒ Object
39
40
41
42
43
44
45
|
# File 'lib/generators/solidus/install/install_generator.rb', line 39
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
|
Instance Method Details
#add_files ⇒ Object
58
59
60
|
# File 'lib/generators/solidus/install/install_generator.rb', line 58
def add_files
template 'config/initializers/spree.rb.tt', 'config/initializers/spree.rb'
end
|
#additional_tweaks ⇒ Object
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
# File 'lib/generators/solidus/install/install_generator.rb', line 72
def additional_tweaks
return unless File.exist? 'public/robots.txt'
append_file "public/robots.txt", " User-agent: *\n Disallow: /checkout\n Disallow: /cart\n Disallow: /orders\n Disallow: /user\n Disallow: /account\n Disallow: /api\n Disallow: /password\n ROBOTS\nend\n".strip_heredoc
|
#complete ⇒ Object
239
240
241
242
243
244
245
246
|
# File 'lib/generators/solidus/install/install_generator.rb', line 239
def complete
unless options[:quiet]
puts "*" * 50
puts "Solidus has been installed successfully. You're all ready to go!"
puts " "
puts "Enjoy!"
end
end
|
106
107
108
109
110
111
112
113
|
# File 'lib/generators/solidus/install/install_generator.rb', line 106
def configure_application
if !options[:enforce_available_locales].nil?
application "# Prevent this deprecation message: https://github.com/svenfuchs/i18n/commit/3b6e56e\nI18n.enforce_available_locales = \#{options[:enforce_available_locales]}\n RUBY\n end\nend\n"
|
#create_database ⇒ Object
148
149
150
151
|
# File 'lib/generators/solidus/install/install_generator.rb', line 148
def create_database
say_status :creating, "database"
rake 'db:create'
end
|
#create_overrides_directory ⇒ Object
102
103
104
|
# File 'lib/generators/solidus/install/install_generator.rb', line 102
def create_overrides_directory
empty_directory "app/overrides"
end
|
#include_seed_data ⇒ Object
135
136
137
138
139
140
141
|
# File 'lib/generators/solidus/install/install_generator.rb', line 135
def include_seed_data
append_file "db/seeds.rb", "\n Spree::Core::Engine.load_seed if defined?(Spree::Core)\n Spree::Auth::Engine.load_seed if defined?(Spree::Auth)\n RUBY\nend\n".strip_heredoc
|
#install_auth_plugin ⇒ Object
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
# File 'lib/generators/solidus/install/install_generator.rb', line 120
def install_auth_plugin
if options[:with_authentication] && (options[:auto_accept] || !no?("
Solidus has a default authentication extension that uses Devise.
You can find more info at https://github.com/solidusio/solidus_auth_devise.
Regardless of what you answer here, it'll be installed if you choose
solidus_starter_frontend as your storefront in a later step.
Would you like to install it? (Y/n)"))
@plugins_to_be_installed << 'solidus_auth_devise'
@plugin_generators_to_run << 'solidus:auth:install'
end
end
|
#install_file_attachment ⇒ Object
62
63
64
65
66
67
68
69
70
|
# File 'lib/generators/solidus/install/install_generator.rb', line 62
def install_file_attachment
if options[:active_storage]
say "Installing Active Storage", :green
rake 'active_storage:install'
else
say "Installing Paperclip", :green
gsub_file 'config/initializers/spree.rb', "ActiveStorageAttachment", "PaperclipAttachment"
end
end
|
#install_frontend ⇒ Object
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
|
# File 'lib/generators/solidus/install/install_generator.rb', line 166
def install_frontend
return if options[:frontend] == 'none'
bundler_context = BundlerContext.new
frontend = detect_frontend_to_install(bundler_context)
(bundler_context) unless frontend == LEGACY_FRONTEND
say_status :installing, frontend
InstallFrontend.
new(bundler_context: bundler_context, generator_context: self).
call(frontend, installer_adds_auth: @plugins_to_be_installed.include?('solidus_auth_devise'))
end
|
#install_migrations ⇒ Object
143
144
145
146
|
# File 'lib/generators/solidus/install/install_generator.rb', line 143
def install_migrations
say_status :copying, "migrations"
`rake railties:install:migrations`
end
|
#install_routes ⇒ Object
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
|
# File 'lib/generators/solidus/install/install_generator.rb', line 215
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
" # This line mounts Solidus's routes at the root of your application.\n # This means, any requests to URLs such as /products, will go to Spree::ProductsController.\n # If you would like to change where this engine is mounted, simply change the :at option to something different.\n #\n # We ask that you don't use the :as option here, as Solidus relies on it being the default of \"spree\"\n \#{CORE_MOUNT_ROUTE}, at: '/'\n\n RUBY\n end\n end\n\n unless options[:quiet]\n puts \"*\" * 50\n puts \"We added the following line to your application's config/routes.rb file:\"\n puts \" \"\n puts \" \#{CORE_MOUNT_ROUTE}, at: '/'\"\n end\nend\n"
|
#load_sample_data ⇒ Object
206
207
208
209
210
211
212
213
|
# File 'lib/generators/solidus/install/install_generator.rb', line 206
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
|
#plugin_install_preparation ⇒ Object
115
116
117
118
|
# File 'lib/generators/solidus/install/install_generator.rb', line 115
def plugin_install_preparation
@plugins_to_be_installed = []
@plugin_generators_to_run = []
end
|
#populate_seed_data ⇒ Object
192
193
194
195
196
197
198
199
200
201
202
203
204
|
# File 'lib/generators/solidus/install/install_generator.rb', line 192
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
|
#prepare_options ⇒ Object
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/generators/solidus/install/install_generator.rb', line 47
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
|
#run_bundle_install_if_needed_by_plugins ⇒ Object
153
154
155
156
157
158
159
160
161
162
163
164
|
# File 'lib/generators/solidus/install/install_generator.rb', line 153
def run_bundle_install_if_needed_by_plugins
@plugins_to_be_installed.each do |plugin_name|
gem plugin_name
end
BundlerContext.bundle_cleanly { run "bundle install" } if @plugins_to_be_installed.any?
run "spring stop" if defined?(Spring)
@plugin_generators_to_run.each do |plugin_generator_name|
generate "#{plugin_generator_name} --skip_migrations=true"
end
end
|
#run_migrations ⇒ Object
182
183
184
185
186
187
188
189
190
|
# File 'lib/generators/solidus/install/install_generator.rb', line 182
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
|
#setup_assets ⇒ Object
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
# File 'lib/generators/solidus/install/install_generator.rb', line 87
def setup_assets
@lib_name = 'spree'
empty_directory 'app/assets/images'
%w{javascripts stylesheets images}.each do |path|
empty_directory "vendor/assets/#{path}/spree/backend" if defined?(Spree::Backend) || Rails.env.test?
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
|