Class: Adminterface::Generators::WebpackerGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Adminterface::Generators::WebpackerGenerator
- Defined in:
- lib/generators/adminterface/webpacker/webpacker_generator.rb
Instance Method Summary collapse
- #install_assets ⇒ Object
- #install_packages ⇒ Object
- #install_webpacker ⇒ Object
- #remove_activeadmin_dependencies ⇒ Object
- #show_readme ⇒ Object
- #update_active_admin_configs ⇒ Object
Instance Method Details
#install_assets ⇒ Object
37 38 39 40 41 |
# File 'lib/generators/adminterface/webpacker/webpacker_generator.rb', line 37 def install_assets template "active_admin.js", "app/javascript/packs/active_admin.js" template "active_admin.scss", "app/javascript/stylesheets/active_admin.scss" template "print.scss", "app/javascript/packs/active_admin/print.scss" end |
#install_packages ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/generators/adminterface/webpacker/webpacker_generator.rb', line 24 def install_packages insert_into_file "config/webpack/environment.js", after: /require\(('|")@rails\/webpacker\1\);?\n/ do <<~EOF environment.loaders.get('sass').use.splice(-1, 0, { loader: 'resolve-url-loader' }) EOF end run "yarn add @cmdbrew/adminterface@#{npm_version}" end |
#install_webpacker ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/generators/adminterface/webpacker/webpacker_generator.rb', line 11 def install_webpacker return if webpacker_installed? puts Rainbow("Adminterface requires webpacker:").yellow if yes?("Install webpacker and continue?") gem "webpacker" rails_command "webpacker:install" else puts Rainbow("Installation aborted").red abort end end |
#remove_activeadmin_dependencies ⇒ Object
47 48 49 50 51 52 |
# File 'lib/generators/adminterface/webpacker/webpacker_generator.rb', line 47 def remove_activeadmin_dependencies run "yarn remove @activeadmin/activeadmin" remove_file "config/webpack/plugins/jquery.js" gsub_file "config/webpack/environment.js", "environment.plugins.prepend('jquery', jquery)\n", "" gsub_file "config/webpack/environment.js", "const jquery = require('./plugins/jquery')\n", "" end |
#show_readme ⇒ Object
54 55 56 |
# File 'lib/generators/adminterface/webpacker/webpacker_generator.rb', line 54 def show_readme readme "README" if behavior == :invoke end |
#update_active_admin_configs ⇒ Object
43 44 45 |
# File 'lib/generators/adminterface/webpacker/webpacker_generator.rb', line 43 def update_active_admin_configs gsub_file "config/initializers/active_admin.rb", "# config.use_webpacker = true", "config.use_webpacker = true" end |