Class: React::Webpack::Generators::InstallGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- React::Webpack::Generators::InstallGenerator
- Defined in:
- lib/generators/react/webpack/install_generator.rb
Instance Method Summary collapse
- #create_base_directories ⇒ Object
- #create_base_files ⇒ Object
- #inject_assets_into_pipeline ⇒ Object
- #install_foreman ⇒ Object
- #install_node_modules ⇒ Object
Instance Method Details
#create_base_directories ⇒ Object
11 12 13 14 |
# File 'lib/generators/react/webpack/install_generator.rb', line 11 def create_base_directories empty_directory("client/components") empty_directory("app/assets/webpack") end |
#create_base_files ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/generators/react/webpack/install_generator.rb', line 16 def create_base_files puts "Creating base files" copy_file "webpack.config.js", "webpack.config.js" copy_file "babelrc", ".babelrc" copy_file "react_helper.rb", "app/helpers/react_helper.rb" copy_file "index.js", "client/index.js" copy_file "Procfile", "Procfile" copy_file "assets.rake", "lib/tasks/assets.rake" end |
#inject_assets_into_pipeline ⇒ Object
46 47 48 49 50 |
# File 'lib/generators/react/webpack/install_generator.rb', line 46 def inject_assets_into_pipeline puts "Injecting assets into pipeline" append_to_file "app/views/layouts/application.html.erb", "<%= javascript_include_tag 'bundle' %>" append_to_file "config/initializers/assets.rb", "Rails.application.config.assets.precompile += %w( bundle.js )" end |
#install_foreman ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/generators/react/webpack/install_generator.rb', line 26 def install_foreman puts "Adding foreman gem" gem "foreman" if yes?("Run bundle install? ( y | n )") system("bundle install") else puts "Cool. Just remember to run 'bundle install' later." end puts "DONE" end |
#install_node_modules ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/generators/react/webpack/install_generator.rb', line 37 def install_node_modules if npm_and_node_installed? initialize_npm_and_node_modules else puts "You'll need to install node & npm to be able to use React." puts "Visit https://nodejs.org/en/ to install." end end |