Class: Solidus::InstallGenerator

Inherits:
Rails::Generators::AppBase
  • Object
show all
Defined in:
lib/generators/solidus/install/install_generator.rb

Constant Summary collapse

CORE_MOUNT_ROUTE =
"mount Spree::Core::Engine"
FRONTENDS =
%w[
  none
  classic
  starter
]
LEGACY_FRONTENDS =
%w[
  solidus_starter_frontend
  solidus_frontend
]
AUTHENTICATIONS =
%w[
  devise
  existing
  custom
  none
]
PAYMENT_METHODS =
{
  name: 'paypal',
  frontends: %w[none classic starter],
  description: 'Install `solidus_paypal_commerce_platform`',
  default: true,
},
{
  name: 'bolt',
  frontends: %w[classic],
  description: 'Install `solidus_bolt`',
  default: false,
},
{
  name: 'braintree',
  frontends: %w[none starter],
  description: 'Install `solidus_braintree`',
  default: false,
},
{
  name: 'none',
  frontends: %w[none classic starter],
  description: 'Skip installing a payment method',
  default: false,
}

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


81
82
83
# File 'lib/generators/solidus/install/install_generator.rb', line 81

def self.exit_on_failure?
  true
end

Instance Method Details

#add_filesObject



112
113
114
# File 'lib/generators/solidus/install/install_generator.rb', line 112

def add_files
  template 'config/initializers/spree.rb.tt', 'config/initializers/spree.rb'
end

#completeObject



219
220
221
# File 'lib/generators/solidus/install/install_generator.rb', line 219

def complete
  say_status :complete, "Solidus has been installed successfully. Enjoy!"
end

#create_databaseObject



154
155
156
157
# File 'lib/generators/solidus/install/install_generator.rb', line 154

def create_database
  say_status :creating, "database"
  rake 'db:create'
end

#create_overrides_directoryObject



139
140
141
# File 'lib/generators/solidus/install/install_generator.rb', line 139

def create_overrides_directory
  empty_directory "app/overrides"
end

#include_seed_dataObject



143
144
145
146
147
# File 'lib/generators/solidus/install/install_generator.rb', line 143

def include_seed_data
  append_file "db/seeds.rb", "    Spree::Core::Engine.load_seed\n  RUBY\nend\n"

#install_authenticationObject



184
185
186
# File 'lib/generators/solidus/install/install_generator.rb', line 184

def install_authentication
  apply_template_for :authentication, @selected_authentication
end

#install_file_attachmentObject



116
117
118
119
120
121
122
123
124
# File 'lib/generators/solidus/install/install_generator.rb', line 116

def install_file_attachment
  if options[:active_storage]
    say_status :assets, "Active Storage", :green
    rake 'active_storage:install'
  else
    say_status :assets, "Paperclip", :green
    gsub_file 'config/initializers/spree.rb', "::ActiveStorageAttachment", "::PaperclipAttachment"
  end
end

#install_frontendObject



188
189
190
# File 'lib/generators/solidus/install/install_generator.rb', line 188

def install_frontend
  apply_template_for :frontend, @selected_frontend
end

#install_migrationsObject



149
150
151
152
# File 'lib/generators/solidus/install/install_generator.rb', line 149

def install_migrations
  say_status :copying, "migrations"
  rake 'railties:install:migrations'
end

#install_payment_methodObject



192
193
194
# File 'lib/generators/solidus/install/install_generator.rb', line 192

def install_payment_method
  apply_template_for :payment_method, @selected_payment_method
end

#install_routesObject



159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/generators/solidus/install/install_generator.rb', line 159

def install_routes
  if Pathname(app_path).join('config', 'routes.rb').read.include? CORE_MOUNT_ROUTE
    say_status :route_exist, CORE_MOUNT_ROUTE, :blue
  else
    route "      # 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    RUBY\n  end\nend\n"

#load_sample_dataObject



210
211
212
213
214
215
216
217
# File 'lib/generators/solidus/install/install_generator.rb', line 210

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

#populate_seed_dataObject



196
197
198
199
200
201
202
203
204
205
206
207
208
# File 'lib/generators/solidus/install/install_generator.rb', line 196

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_optionsObject



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
# File 'lib/generators/solidus/install/install_generator.rb', line 85

def prepare_options
  @run_migrations = options[:migrate]
  @load_seed_data = options[:seed] && @run_migrations
  @load_sample_data = options[:sample] && @run_migrations && @load_seed_data
  @selected_frontend = detect_frontend_to_install
  @selected_authentication = detect_authentication_to_install
  @selected_payment_method = detect_payment_method_to_install

  # Silence verbose output (e.g. Rails migrations will rely on this environment variable)
  ENV['VERBOSE'] = 'false'

  # No reason to check for their presence if we're about to install them
  ENV['SOLIDUS_SKIP_MIGRATIONS_CHECK'] = 'true'

  if options[:enforce_available_locales] != nil
    warn \
      "DEPRECATION WARNING: using `solidus:install --enforce-available-locales` is now deprecated and has no effect. " \
      "Since Rails 4.1 the default is `true` so we no longer need to explicitly set a value."
  end

  if options[:lib_name] != nil
    warn \
      "DEPRECATION WARNING: using `solidus:install --lib-name` is now deprecated and has no effect. " \
      "The option is legacy and should be removed from scripts still using it."
  end
end

#run_migrationsObject



174
175
176
177
178
179
180
181
182
# File 'lib/generators/solidus/install/install_generator.rb', line 174

def run_migrations
  if @run_migrations
    say_status :running, "migrations"

    rake 'db:migrate'
  else
    say_status :skipping, "migrations (don't forget to run rake db:migrate)"
  end
end

#setup_assetsObject



126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/generators/solidus/install/install_generator.rb', line 126

def setup_assets
  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