Class: WebpackIntegrator::InstallGenerator

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

Instance Method Summary collapse

Instance Method Details

#add_client_routeObject



24
25
26
27
# File 'lib/generators/webpack_integrator/install_generator.rb', line 24

def add_client_route
  route "match '*path/', to: 'client#index', format: false, via: :get"
  route "root 'client#index'"
end

#add_gemsObject



20
21
22
23
# File 'lib/generators/webpack_integrator/install_generator.rb', line 20

def add_gems
  gem "foreman", group: :development
  run "bundle"
end

#add_public_webpack_dir_to_gitignoreObject



28
29
30
# File 'lib/generators/webpack_integrator/install_generator.rb', line 28

def add_public_webpack_dir_to_gitignore
  system 'echo "public/webpack" >> .gitignore'
end

#add_yarn_dependenciesObject



17
18
19
# File 'lib/generators/webpack_integrator/install_generator.rb', line 17

def add_yarn_dependencies
  run "cd client && yarn add webpack webpack-cli babel-loader babel-preset-es2015"
end

#copy_install_fileObject



7
8
9
10
11
12
13
14
15
16
# File 'lib/generators/webpack_integrator/install_generator.rb', line 7

def copy_install_file
  files = %w[client/webpack.config.js
             client/package.json
             client/.babelrc
             client/src/index.js
             app/controllers/client_controller.rb
             app/views/client/index.html.erb
             Procfile.dev]
  files.each {|file| copy_file(file,file)}
end


31
32
33
34
35
36
37
# File 'lib/generators/webpack_integrator/install_generator.rb', line 31

def print_message
  puts "    ++++++++++++++++++++++++++++++++++++++"
  puts "    Thank you for using webpack_integrator!"
  puts "    Please add the following line to your app/views/layouts/application.html.erb header:"
  puts "    <%= javascript_include_tag '/webpack/index-bundle.js' %>"
  puts "    ++++++++++++++++++++++++++++++++++++++"
end