Class: Geoblacklight::Assets::ViteGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Geoblacklight::Assets::ViteGenerator
- Defined in:
- lib/generators/geoblacklight/assets/vite_generator.rb
Instance Method Summary collapse
-
#add_frontend ⇒ Object
Pick a version of the frontend asset package and install it.
-
#add_javascript ⇒ Object
Replace the default generated Vite entrypoint with our own.
-
#add_stylesheets ⇒ Object
Add our own stylesheets that reference the versions from npm.
-
#bundle_install ⇒ Object
This will write its own package.json if one doesn’t exist, causing a conflict, so it needs to happen after we copy ours.
-
#copy_config_vite_json ⇒ Object
Copy Vite config files.
-
#geoblacklight_base_layout ⇒ Object
Add our version of the Blacklight base layout with Vite helper tags.
-
#install_dependencies ⇒ Object
Add our package.json with non-GBL dependencies (Blacklight, Bootstrap, etc.).
-
#install_vite ⇒ Object
Install Vite.
Instance Method Details
#add_frontend ⇒ Object
Pick a version of the frontend asset package and install it.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/generators/geoblacklight/assets/vite_generator.rb', line 53 def add_frontend # If in local development or CI, install the version we made linkable in # the test app generator. This will make it so changes made in the outer # directory are picked up automatically, like a symlink. Note that this # does NOT install the dependencies of the package, so we have to make # sure to install those separately. See: # https://classic.yarnpkg.com/lang/en/docs/cli/link/ # https://github.com/yarnpkg/yarn/issues/2914 if [:test] run "yarn link @geoblacklight/frontend" # If a branch was specified (e.g. you are running a template.rb build # against a test branch), use the latest version available on npm elsif ENV["BRANCH"] run "yarn add @geoblacklight/frontend@latest" # Otherwise, pick the version from npm that matches our Geoblacklight # gem version else run "yarn add @geoblacklight/frontend@#{Geoblacklight::VERSION}" end end |
#add_javascript ⇒ Object
Replace the default generated Vite entrypoint with our own
84 85 86 87 |
# File 'lib/generators/geoblacklight/assets/vite_generator.rb', line 84 def add_javascript remove_file "app/javascript/entrypoints/application.js" copy_file "assets/application.js", "app/javascript/entrypoints/application.js" end |
#add_stylesheets ⇒ Object
Add our own stylesheets that reference the versions from npm
77 78 79 80 81 |
# File 'lib/generators/geoblacklight/assets/vite_generator.rb', line 77 def add_stylesheets copy_file "assets/_customizations.scss", "app/javascript/stylesheets/_customizations.scss" copy_file "assets/geoblacklight.scss", "app/javascript/stylesheets/geoblacklight.scss" copy_file "assets/application.scss", "app/javascript/entrypoints/application.scss" end |
#bundle_install ⇒ Object
This will write its own package.json if one doesn’t exist, causing a conflict, so it needs to happen after we copy ours
48 49 50 |
# File 'lib/generators/geoblacklight/assets/vite_generator.rb', line 48 def bundle_install run "bundle exec vite install" end |
#copy_config_vite_json ⇒ Object
Copy Vite config files
35 36 37 38 |
# File 'lib/generators/geoblacklight/assets/vite_generator.rb', line 35 def copy_config_vite_json copy_file "vite.json", "config/vite.json" copy_file "vite.config.ts", "vite.config.ts" end |
#geoblacklight_base_layout ⇒ Object
Add our version of the Blacklight base layout with Vite helper tags
30 31 32 |
# File 'lib/generators/geoblacklight/assets/vite_generator.rb', line 30 def geoblacklight_base_layout copy_file "base.html.erb", "app/views/layouts/blacklight/base.html.erb" end |
#install_dependencies ⇒ Object
Add our package.json with non-GBL dependencies (Blacklight, Bootstrap, etc.)
41 42 43 44 |
# File 'lib/generators/geoblacklight/assets/vite_generator.rb', line 41 def install_dependencies copy_file "package.json", "package.json" run "yarn install" end |
#install_vite ⇒ Object
Install Vite
24 25 26 27 |
# File 'lib/generators/geoblacklight/assets/vite_generator.rb', line 24 def install_vite gem "vite_rails", "~> 3.0" run "bundle install" end |