Class: Repack::GodInstallGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Repack::GodInstallGenerator
- Defined in:
- lib/generators/repack/god_install_generator.rb
Overview
:nodoc:
Class Method Summary collapse
Instance Method Summary collapse
- #add_to_gitignore ⇒ Object
- #check_god_mode ⇒ Object
- #copy_package_json ⇒ Object
- #copy_webpack_conf ⇒ Object
- #create_webpack_application_js ⇒ Object
- #finishing_god_move ⇒ Object
- #layouts ⇒ Object
- #whats_next ⇒ Object
Class Method Details
.frontend_config(frontend_gem, sheet_imports, sheet_name = 'application.css', new_sheet_name = 'application.scss') ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/generators/repack/god_install_generator.rb', line 75 def self.frontend_config(frontend_gem, sheet_imports, sheet_name = 'application.css', new_sheet_name = 'application.scss') begin gem frontend_gem File.rename "app/assets/stylesheets/#{sheet_name}", "app/assets/stylesheets/#{new_sheet_name}" File.open("app/assets/stylesheets/#{new_sheet_name}", 'w+') do |f| sheet_imports.each do |import| f.write("@import #{import}; \n") end end rescue => e puts "Error While Setting Up Frontend Framework: #{e}" end end |
Instance Method Details
#add_to_gitignore ⇒ Object
65 66 67 68 69 70 71 72 73 |
# File 'lib/generators/repack/god_install_generator.rb', line 65 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 |
#check_god_mode ⇒ Object
7 8 9 10 11 |
# File 'lib/generators/repack/god_install_generator.rb', line 7 def check_god_mode unless yes?('Is this a new application? (yes \ no)') raise 'GOD MODE is for new apps only. Run again at your own risk!' end end |
#copy_package_json ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/generators/repack/god_install_generator.rb', line 13 def copy_package_json copy_file "package.json", "package.json" insert_into_file './package.json', after: /dependencies\": {\n/ do " \"react-router\": \"^2.4.1\",\n \"react-redux\": \"^4.4.5\",\n \"redux\": \"^3.5.2\",\n \"redux-thunk\": \"^2.1.0\",\n \"react-router-redux\": \"^4.0.5\",\n \"redux-auth-wrapper\": \"^1.0.0\",\n RUBY\n end\nend\n" |
#copy_webpack_conf ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/generators/repack/god_install_generator.rb', line 27 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
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/generators/repack/god_install_generator.rb', line 37 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" end |
#finishing_god_move ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/generators/repack/god_install_generator.rb', line 89 def finishing_god_move base_sheet_path = "app/assets/stylesheets" nav_template = ask('Frontend Framework: 1) Materialize, 2) Bootstrap, 3) None').strip case nav_template when '1' sheet_imports = [ 'materialize', 'alert' ] gem 'materialize-sass' if File.exists? "#{base_sheet_path}/application.css" File.rename "#{base_sheet_path}/application.css", "#{base_sheet_path}/application.scss" end File.open("#{base_sheet_path}/application.scss", 'w+') do |f| sheet_imports.each do |import| f.write("@import '#{import}'; \n") end end copy_file "boilerplate/god_mode/components/MaterialNavbar.js", "client/components/Navbar.js" when '2' sheet_imports = [ 'bootstrap-sprockets', 'bootstrap', 'alert' ] gem 'bootstrap-sass' if File.exists? "#{base_sheet_path}/application.css" File.rename "#{base_sheet_path}/application.css", "#{base_sheet_path}/application.scss" end File.open("#{base_sheet_path}/application.scss", 'w+') do |f| sheet_imports.each do |import| f.write("@import '#{import}'; \n") end end copy_file "boilerplate/god_mode/components/BootstrapNavbar.js", "client/components/Navbar.js" when '3' puts 'No Navbar template, all the components are ready for you to implement however you want.' else puts 'Wrong template choice, try again!' finishing_god_move end if nav_template == '3' copy_file "boilerplate/god_mode/containers/NoNavApp.js", "client/containers/App.js" else copy_file "boilerplate/god_mode/containers/TokenApp.js", "client/containers/App.js" end copy_file "boilerplate/router_redux/application.js", "client/application.js" copy_file "boilerplate/god_mode/tokenRoutes.js", "client/routes.js" copy_file "boilerplate/router_redux/store.js", "client/store.js" copy_file "boilerplate/router/NoMatch.js", "client/components/NoMatch.js" copy_file "boilerplate/god_mode/actions/tokenAuth.js", "client/actions/auth.js" copy_file "boilerplate/god_mode/actions/flash.js", "client/actions/flash.js" copy_file "boilerplate/god_mode/components/FlashMessage.js", "client/components/FlashMessage.js" copy_file "boilerplate/god_mode/components/Login.js", "client/components/Login.js" copy_file "boilerplate/god_mode/components/SignUp.js", "client/components/SignUp.js" copy_file "boilerplate/god_mode/components/Loading.js", "client/components/Loading.js" copy_file "boilerplate/god_mode/reducers/auth.js", "client/reducers/auth.js" copy_file "boilerplate/god_mode/reducers/flash.js", "client/reducers/flash.js" copy_file "boilerplate/god_mode/reducers/index.js", "client/reducers/index.js" copy_file "boilerplate/god_mode/scss/alert.css.scss", "app/assets/stylesheets/alert.css.scss" gem "devise" gem 'omniauth' gem 'devise_token_auth' insert_into_file './package.json', after: /dependencies\": {\n/ do " \"j-toker\": \"^0.0.10-beta3\",\n RUBY\nend\n\n insert_into_file './app/controllers/application_controller.rb', after: /ActionController::Base\\n/ do\n <<-'RUBY'\n skip_before_action :verify_authenticity_token\n RUBY\nend\n\n Bundler.with_clean_env do\n run \"bundle update\"\n end\n \n run 'bin/spring stop'\n generate \"devise:install\"\n run \"bundle exec rake db:create\"\n model_name = ask(\"What would you like the devise model to be called? [user]\")\n model_name = \"user\" if model_name.blank?\n\n mount_point = ask(\"Auth Mount Point [api/auth]\")\n mount_point = \"api/auth\" if mount_point.blank?\n generate \"devise_token_auth:install \#{model_name.titleize} \#{mount_point}\"\n\n run 'bundle exec rake db:migrate'\nend\n" |
#layouts ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/generators/repack/god_install_generator.rb', line 48 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
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 |
# File 'lib/generators/repack/god_install_generator.rb', line 177 def whats_next puts " \u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2588\u2557 \u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2557 \n \u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D \u2588\u2588\u2554\u2550\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D \u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2551 \u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\n \u2588\u2588\u2551 \u2588\u2588\u2588\u2557\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2554\u2588\u2588\u2588\u2588\u2554\u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2554\u2588\u2588\u2557 \u2588\u2588\u2551\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2551\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D\u2588\u2588\u2551 \u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2551 \u2588\u2588\u2551\n \u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2551\u255A\u2588\u2588\u2554\u255D\u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u255D \u2588\u2588\u2554\u2550\u2550\u255D \u2588\u2588\u2551\u255A\u2588\u2588\u2557\u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2551 \u2588\u2588\u2554\u2550\u2550\u255D \u2588\u2588\u2551 \u2588\u2588\u2551\n \u255A\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D\u255A\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D \u2588\u2588\u2551 \u255A\u2550\u255D \u2588\u2588\u2551\u255A\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2551 \u255A\u2588\u2588\u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D\n \u255A\u2550\u2550\u2550\u2550\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u2550\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u255D\u255A\u2550\u2550\u2550\u2550\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u2550\u255D\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u255D\u255A\u2550\u2550\u2550\u2550\u2550\u255D \n\n Note: If you chose a frontend framework (Materialize / Bootstrap) you still need to install the gem and configure it in your project.\n\n EOF\n puts <<-EOF.strip_heredoc\n 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 |