From 2ab6df24f6b57f3f5221c01169ca707a2b999ca6 Mon Sep 17 00:00:00 2001 From: George Mendoza Date: Fri, 18 Feb 2022 16:50:59 +0800 Subject: [PATCH 1/2] Fix: frontend assets should be added to vendor Goal ---- We want the frontend assets and directories added to a Solidus app because Solidus extensions assume that these files and directories exist. The Solidus extensions typically link these pre-existing files to their assets. Expected behavior ----------------- Given I have a Solidus app without a frontend When I apply the SolidusStarterFrontend template to the app Then I should see the following frontend assets and directories added to the app: * `vendor/assets/images/spree/frontend` * `vendor/assets/javascripts/spree/frontend/all.js` * `vendor/assets/stylesheets/spree/frontend/all.css` Current behavior ---------------- SolidusStarterFrontend doesn't add the frontend assets and directories to the app's vendor directory. Bug cause --------- Prior to https://github.com/solidusio/solidus/pull/4251, the Solidus Install generator was adding the frontend assets during installation even if the app didn't have `solidus_frontend` in its bundle. With the issue fixed, SolidusStarterFrontend has to be updated to add these frontend assets by itself. Implementation -------------- This copies as-is the vendored assets of solidus_frontend from https://github.com/solidusio/solidus/tree/master/core/lib/generators/solidus/install/templates/vendor/assets. --- template.rb | 9 +++++++++ templates/vendor/assets/images/spree/frontend/.gitkeep | 0 .../vendor/assets/javascripts/spree/frontend/all.js | 10 ++++++++++ .../vendor/assets/stylesheets/spree/frontend/all.css | 9 +++++++++ 4 files changed, 28 insertions(+) create mode 100644 templates/vendor/assets/images/spree/frontend/.gitkeep create mode 100644 templates/vendor/assets/javascripts/spree/frontend/all.js create mode 100644 templates/vendor/assets/stylesheets/spree/frontend/all.css diff --git a/template.rb b/template.rb index b3c53d2c..16d38c7d 100644 --- a/template.rb +++ b/template.rb @@ -76,6 +76,15 @@ def copy_solidus_starter_frontend_files prepend_file 'config/routes.rb', File.read('tmp/routes.rb') directory 'spec' + directory 'vendor', force: forcefully_replace_any_solidus_frontend_assets? +end + +# In CI, the Rails environment is test. In that Rails environment, +# `Solidus::InstallGenerator#setup_assets` adds `solidus_frontend` assets to +# vendor. We'd want to forcefully replace those `solidus_frontend` assets with +# SolidusStarterFrontend assets in CI. +def forcefully_replace_any_solidus_frontend_assets? + Rails.env.test? end def update_asset_files diff --git a/templates/vendor/assets/images/spree/frontend/.gitkeep b/templates/vendor/assets/images/spree/frontend/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/templates/vendor/assets/javascripts/spree/frontend/all.js b/templates/vendor/assets/javascripts/spree/frontend/all.js new file mode 100644 index 00000000..abb7d1f5 --- /dev/null +++ b/templates/vendor/assets/javascripts/spree/frontend/all.js @@ -0,0 +1,10 @@ +// This is a manifest file that'll be compiled into including all the files listed below. +// Add new JavaScript/Coffee code in separate files in this directory and they'll automatically +// be included in the compiled file accessible from http://example.com/assets/application.js +// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the +// the compiled file. +// +//= require jquery +//= require rails-ujs +//= require spree/frontend +//= require_tree . diff --git a/templates/vendor/assets/stylesheets/spree/frontend/all.css b/templates/vendor/assets/stylesheets/spree/frontend/all.css new file mode 100644 index 00000000..ed0e9569 --- /dev/null +++ b/templates/vendor/assets/stylesheets/spree/frontend/all.css @@ -0,0 +1,9 @@ +/* + * This is a manifest file that'll automatically include all the stylesheets available in this directory + * and any sub-directories. You're free to add application-wide styles to this file and they'll appear at + * the top of the compiled file, but it's generally better to create a new file per style scope. + * + *= require spree/frontend + *= require_self + *= require_tree . +*/ From 0950fca70a627b63473892973e24a4f3af513880 Mon Sep 17 00:00:00 2001 From: George Mendoza Date: Tue, 22 Feb 2022 17:51:16 +0800 Subject: [PATCH 2/2] Remove jQuery dependency copied from solidus_frontend vendor assets --- templates/vendor/assets/javascripts/spree/frontend/all.js | 1 - 1 file changed, 1 deletion(-) diff --git a/templates/vendor/assets/javascripts/spree/frontend/all.js b/templates/vendor/assets/javascripts/spree/frontend/all.js index abb7d1f5..1fb36198 100644 --- a/templates/vendor/assets/javascripts/spree/frontend/all.js +++ b/templates/vendor/assets/javascripts/spree/frontend/all.js @@ -4,7 +4,6 @@ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the // the compiled file. // -//= require jquery //= require rails-ujs //= require spree/frontend //= require_tree .