Class: Repack::InstallGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Repack::InstallGenerator
- Defined in:
- lib/generators/repack/install_generator.rb
Overview
:nodoc:
Instance Method Summary collapse
- #add_to_gitignore ⇒ Object
- #copy_package_json ⇒ Object
- #copy_webpack_conf ⇒ Object
- #create_webpack_application_js ⇒ Object
- #layouts ⇒ Object
- #whats_next ⇒ Object
Instance Method Details
#add_to_gitignore ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'lib/generators/repack/install_generator.rb', line 51 def add_to_gitignore append_to_file ".gitignore" do " /node_modules\n /public/webpack\n npm-debug.log\n EOF\n end\nend\n".strip_heredoc |
#copy_package_json ⇒ Object
7 8 9 |
# File 'lib/generators/repack/install_generator.rb', line 7 def copy_package_json copy_file "package.json", "package.json" end |
#copy_webpack_conf ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/generators/repack/install_generator.rb', line 11 def copy_webpack_conf copy_file "webpack.config.js", "config/webpack.config.js" if yes?('Are you going to be deploying to heroku? (yes \ no)') puts 'Copying Heroku Webpack Config!' copy_file "webpack.config.heroku.js", "config/webpack.config.heroku.js" puts 'Adding Basic Puma Proc File' copy_file "Procfile", 'Procfile' end end |
#create_webpack_application_js ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/generators/repack/install_generator.rb', line 21 def create_webpack_application_js empty_directory "client" empty_directory "client/containers" empty_directory "client/components" empty_directory "client/__tests__" empty_directory "client/__tests__/__mocks__" copy_file "babelrc", "./.babelrc" copy_file "styleMock.js", "client/__tests__/__mocks__/styleMock.js" copy_file "fileMock.js", "client/__tests__/__mocks__/fileMock.js" copy_file "boilerplate/application.js", "client/application.js" copy_file "boilerplate/App.js", "client/containers/App.js" end |
#layouts ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/generators/repack/install_generator.rb', line 34 def layouts layouts_dir = 'app/views/layouts' application_view = "#{layouts_dir}/application.html.erb" insert_into_file application_view, before: /<\/head>/ do "<% if Rails.env.development? %>\n <script src=\"http://localhost:3808/webpack-dev-server.js\"></script>\n<% end %>\n RUBY\n end\n insert_into_file application_view, before: /<\\/body>/ do <<-'RUBY'\n<%= javascript_include_tag *webpack_asset_paths('application') %>\n RUBY\n end\nend\n" |
#whats_next ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/generators/repack/install_generator.rb', line 61 def whats_next puts " We've set up the basics of repack for you, but you'll still\n need to:\n 1. yarn install or npm install\n 2. Add an element with an id of 'app' to your layout\n 3. To disable hot module replacement remove <script src=\"http://localhost:3808/webpack-dev-server.js\"></script> from layout\n 4. Run 'yarn / npm dev_server' to run the webpack-dev-server\n 5. Run 'bundle exec rails s' to run the rails server (both servers must be running)\n 6. If you are using react-router or god mode and want to sync server routes add:\n get '*unmatched_route', to: <your client controller>#<default action>\n This must be the very last route in your routes.rb file\n e.g. get '*unmatched_route', to: 'home#index'\n FOR HEROKU DEPLOYS:\n 1. yarn / npm heroku-setup\n 2. Push to heroku the post-build hook will take care of the rest\n See the README.md for this gem at\n https://github.com/cottonwoodcoding/repack/blob/master/README.md\n for more info.\n \n Thanks for using Repack!\n EOF\nend\n".strip_heredoc |