Class: Spree::Storefront::Generators::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/spree/storefront/install/install_generator.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.source_pathsObject



11
12
13
14
15
16
17
# File 'lib/generators/spree/storefront/install/install_generator.rb', line 11

def self.source_paths
  [
    File.expand_path('templates', __dir__),
    File.expand_path('../templates', "../#{__FILE__}"),
    File.expand_path('../templates', "../../#{__FILE__}")
  ]
end

Instance Method Details

#installObject



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

def install
  empty_directory Rails.root.join('app/assets/tailwind') if Rails.root && !Rails.root.join('app/assets/tailwind').exist?
  template 'application.css', 'app/assets/tailwind/application.css', force: options[:force]
  template 'tailwind.config.js', 'config/tailwind.config.js', force: options[:force]

  if Rails.root && Rails.root.join("Procfile.dev").exist?
    append_to_file 'Procfile.dev', "\nstorefront_css: bin/rails tailwindcss:watch" unless File.read('Procfile.dev').include?('storefront_css:')
  else
    create_file 'Procfile.dev', "storefront_css: bin/rails tailwindcss:watch\n"
  end

  say "Add bin/dev to start foreman"
  copy_file "dev", "bin/dev", force: true
  chmod "bin/dev", 0755, verbose: false

  empty_directory Rails.root.join('app/assets/builds') if Rails.root

  unless File.exist?('app/assets/config/manifest.js')
    create_file 'app/assets/config/manifest.js', "//= link_tree ../builds\n"

    say "Ensure foreman is installed"
    run "gem install foreman"
  else
    append_to_file 'app/assets/config/manifest.js', "\n//= link_tree ../builds" unless File.read('app/assets/config/manifest.js').include?('//= link_tree ../builds')
  end

  # remove static robots.txt as storefront serves it dynamically via seo#robots
  remove_file 'public/robots.txt'
end

#install_page_builderObject



19
20
21
22
23
# File 'lib/generators/spree/storefront/install/install_generator.rb', line 19

def install_page_builder
  say_status :installing, 'page builder'
  migrate_option = options[:migrate] == false ? ' --migrate=false' : ''
  generate "spree:page_builder:install --force#{migrate_option}"
end