Class: DiscoApp::Generators::ReactGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- DiscoApp::Generators::ReactGenerator
- Defined in:
- lib/generators/disco_app/react/react_generator.rb
Instance Method Summary collapse
- #bundle_install ⇒ Object
- #configure_api ⇒ Object
- #configure_api_response ⇒ Object
- #configure_application ⇒ Object
- #configure_gemfile ⇒ Object
- #configure_react ⇒ Object
- #configure_serializers ⇒ Object
- #configure_views ⇒ Object
- #configure_webpack ⇒ Object
- #install_webpacker ⇒ Object
- #prepare_application ⇒ Object
- #update_routes ⇒ Object
- #yarn_install ⇒ Object
Instance Method Details
#bundle_install ⇒ Object
19 20 21 22 23 |
# File 'lib/generators/disco_app/react/react_generator.rb', line 19 def bundle_install Bundler.with_clean_env do run 'bundle install' end end |
#configure_api ⇒ Object
82 83 84 |
# File 'lib/generators/disco_app/react/react_generator.rb', line 82 def configure_api directory 'app/controllers/embedded' end |
#configure_api_response ⇒ Object
95 96 97 |
# File 'lib/generators/disco_app/react/react_generator.rb', line 95 def configure_api_response copy_file 'app/models/api_response.rb' end |
#configure_application ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/generators/disco_app/react/react_generator.rb', line 25 def configure_application application 'config.middleware.use OliveBranch::Middleware' application '# Camel-case to underscore transformation for JSON requests.' copy_file 'config/initializers/mime_types.rb' copy_file 'config/initializers/omniauth.rb' template 'config/initializers/version.rb.tt', 'config/initializers/version.rb' %w[.env .env.local].each do |file| append_to_file file, 'BUGSNAG_API_KEY=00000000' end end |
#configure_gemfile ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/generators/disco_app/react/react_generator.rb', line 11 def configure_gemfile gem 'fast_jsonapi' gem 'multi_json' gem 'oj' gem 'olive_branch' gem 'webpacker' end |
#configure_react ⇒ Object
99 100 101 102 103 104 |
# File 'lib/generators/disco_app/react/react_generator.rb', line 99 def configure_react directory 'app/webpack/javascripts' directory 'app/webpack/stylesheets' copy_file 'app/webpack/packs/embedded.js' remove_file 'app/webpack/packs/application.js' end |
#configure_serializers ⇒ Object
91 92 93 |
# File 'lib/generators/disco_app/react/react_generator.rb', line 91 def configure_serializers directory 'app/serializers' end |
#configure_views ⇒ Object
86 87 88 89 |
# File 'lib/generators/disco_app/react/react_generator.rb', line 86 def configure_views directory 'app/views/embedded' copy_file 'app/views/layouts/embedded.html.erb' end |
#configure_webpack ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/generators/disco_app/react/react_generator.rb', line 64 def configure_webpack %w[.eslintignore .eslintrc .prettierrc babel.config.js postcss.config.js].each do |file| copy_file "root/#{file}", file end template 'root/package.json.tt', 'package.json' copy_file 'config/webpacker.yml' copy_file 'config/webpack/staging.js' copy_file 'config/webpack/test.js' run "if [ -d 'app/javascript' ]; then mv -f app/javascript app/webpack; fi" end |
#install_webpacker ⇒ Object
60 61 62 |
# File 'lib/generators/disco_app/react/react_generator.rb', line 60 def install_webpacker rake 'webpacker:install' end |
#prepare_application ⇒ Object
7 8 9 |
# File 'lib/generators/disco_app/react/react_generator.rb', line 7 def prepare_application copy_file 'root/VERSION', 'VERSION' end |
#update_routes ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/generators/disco_app/react/react_generator.rb', line 38 def update_routes routes = <<-ROUTES.gsub(/^ {8}/, '') # Embedded React routes. root to: 'embedded/home#index' # Embedded API. namespace :embedded do namespace :api, constraints: { format: :json }, defaults: { format: :json } do resource :shop, only: [:show] resources :users, only: [] do get :current, on: :collection end end end ROUTES route routes comment_lines 'config/routes.rb', "root to: 'home#index'" end |
#yarn_install ⇒ Object
78 79 80 |
# File 'lib/generators/disco_app/react/react_generator.rb', line 78 def yarn_install run 'yarn install' end |