Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make it possible to use importmap and propshaft together when generating #3249

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
ruby-version: 3.2
bundler: "latest"
- name: Change permissions
run: chmod -R o-w /opt/hostedtoolcache/Ruby/3.2.4/x64/lib/ruby/gems/3.2.0/gems
run: "chmod -f -R o-w /opt/hostedtoolcache/Ruby/3.2.5/x64/lib/ruby/gems/3.2.0/gems | :"
- name: Install dependencies
run: bundle install
- name: Run linter
Expand Down Expand Up @@ -85,7 +85,7 @@ jobs:
bundler: "latest"
ruby-version: ${{ matrix.ruby }}
- name: Change permissions
run: chmod -R o-w /opt/hostedtoolcache/Ruby/3.2.4/x64/lib/ruby/gems/3.2.0/gems
run: "chmod -f -R o-w /opt/hostedtoolcache/Ruby/3.2.5/x64/lib/ruby/gems/3.2.0/gems | :"
- name: Install dependencies
run: bundle install
- name: Run tests
Expand All @@ -95,4 +95,4 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Build docker image
run: docker-compose build app
run: docker compose build app
28 changes: 21 additions & 7 deletions lib/generators/blacklight/assets/importmap_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ def import_javascript_assets
CONTENT
end

# NOTE: manifest may not exist if they installed with "-a propshaft"
return unless File.exist?('app/assets/config/manifest.js')

append_to_file 'app/assets/config/manifest.js' do
<<~CONTENT
//= link blacklight/manifest.js
Expand All @@ -28,23 +31,34 @@ def import_javascript_assets
end

def append_blacklight_javascript
# NOTE: Avoid reimport of bootstrap (if they ran --css=bootstrap)
# see https://github.com/rails/cssbundling-rails/blob/4f4c62148bbee215a4694d6970be30f17c3066dd/lib/install/bootstrap/install.rb#L17-L20
append_to_file "app/javascript/application.js", %(import * as bootstrap from "bootstrap"\n)
append_to_file 'app/javascript/application.js' do
<<~CONTENT
import bootstrap from "bootstrap"
import githubAutoCompleteElement from "@github/auto-complete-element"
import Blacklight from "blacklight"
CONTENT
end
end

def add_stylesheet
gem "sassc-rails", "~> 2.1" if Rails.version > '7'
# NOTE: this indicates they installed with --css=bootstrap
if File.exist?('app/assets/stylesheets/application.bootstrap.scss')
append_to_file 'app/assets/stylesheets/application.bootstrap.scss' do
<<~CONTENT
@import "blacklight-frontend/app/assets/stylesheets/blacklight/blacklight";
CONTENT
end
else
gem "sassc-rails", "~> 2.1" if Rails.version > '7'

create_file 'app/assets/stylesheets/blacklight.scss' do
<<~CONTENT
@import 'bootstrap';
@import 'blacklight/blacklight';
CONTENT
create_file 'app/assets/stylesheets/blacklight.scss' do
<<~CONTENT
@import 'bootstrap';
@import 'blacklight/blacklight';
CONTENT
end
end
end

Expand Down
6 changes: 3 additions & 3 deletions lib/generators/blacklight/assets_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ class AssetsGenerator < Rails::Generators::Base
def run_asset_pipeline_specific_generator
generated_options = "--bootstrap-version='#{options[:'bootstrap-version']}'" if options[:'bootstrap-version']

generator = if defined?(Propshaft)
'blacklight:assets:propshaft'
elsif defined?(Importmap)
generator = if defined?(Importmap)
'blacklight:assets:importmap'
elsif defined?(Propshaft)
'blacklight:assets:propshaft'
elsif defined?(Sprockets)
'blacklight:assets:sprockets'
end
Expand Down
Loading