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



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

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

Instance Method Details

#installObject



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

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'
  template 'tailwind.config.js', 'config/tailwind.config.js'

  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 we use robots.txt.erb
  remove_file Rails.root.join('public/robots.txt') if Rails.root && Rails.root.join('public/robots.txt').exist?
end