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
    "    # Added by webpacked\n    /node_modules\n    /public/assets/webpacked\n    EOF\n  end\nend\n".strip_heredoc

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