Class: Webpacked::InstallGenerator

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

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#add_to_gitignoreObject



27
28
29
30
31
32
33
34
35
# File 'lib/generators/webpacked/install_generator.rb', line 27

def add_to_gitignore
  append_to_file '.gitignore' do
    <<-EOF.strip_heredoc
    # Added by webpacked
    /node_modules
    /public/assets/webpacked
    EOF
  end
end

#copy_frontend_dirObject



14
15
16
# File 'lib/generators/webpacked/install_generator.rb', line 14

def copy_frontend_dir
  directory 'frontend'
end

#prepare_package_jsonObject



18
19
20
21
22
23
24
25
# File 'lib/generators/webpacked/install_generator.rb', line 18

def prepare_package_json
  get 'package.json' do |content|
    content.gsub!(/\{\{(.+?)\}\}/) do
      Rails.configuration.webpacked.send(Regexp.last_match(1))
    end
    create_file 'package.json', content
  end
end

#run_npm_installObject



37
38
39
# File 'lib/generators/webpacked/install_generator.rb', line 37

def run_npm_install
  run 'npm install' if yes?("Run 'npm install' for you?")
end

#use_foremanObject



6
7
8
9
10
11
12
# File 'lib/generators/webpacked/install_generator.rb', line 6

def use_foreman
  if yes?('Would you like to use foreman to start webpack-dev-server and rails server at same time?')
    gem 'foreman'
    copy_file 'Procfile'
    run 'bundle install' if yes?("Run 'bundle install' for you?")
  end
end

#whats_nextObject



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/generators/webpacked/install_generator.rb', line 41

def whats_next
  puts <<-EOF.strip_heredoc
    Base webpacked setup completed. Now you can:
      1. Include 'Webpacked::ControllerHelper' into 'ApplicationController'
         and set up entry points for your controllers via 'webpacked_entry' class method
      2. Add the webpacked helpers into your layout instead of regular Rails helpers
      3. Run 'npm run dev:server' to start webpack-dev-server or 'foreman start' to start it alongside rails server
    See https://github.com/Darkside73/webpacked for more info.
    Thanks for using webpacked gem ;)
  EOF
end