From fee90809fdfe6dd7589ac7a856123c2c80922a4c Mon Sep 17 00:00:00 2001 From: Jonathan Hefner Date: Sat, 13 Jan 2024 16:38:24 -0600 Subject: [PATCH] Use Thor's `apply` instead of a prerequisite task The `css:install:shared` task serves only as a prerequisite for the other installer tasks; it should not be run on its own (nor listed with `rake --tasks`). By replacing this task with corresponding calls to Thor's `apply` method, we avoid the overhead of running `bin/rails app:template` (and `bundle install`) multiple times. --- lib/install/bootstrap/install.rb | 2 ++ lib/install/bulma/install.rb | 2 ++ lib/install/postcss/install.rb | 2 ++ lib/install/sass/install.rb | 2 ++ lib/install/tailwind/install.rb | 2 ++ lib/tasks/cssbundling/install.rake | 15 +++++---------- 6 files changed, 15 insertions(+), 10 deletions(-) diff --git a/lib/install/bootstrap/install.rb b/lib/install/bootstrap/install.rb index bfea9b0..f00991e 100644 --- a/lib/install/bootstrap/install.rb +++ b/lib/install/bootstrap/install.rb @@ -1,6 +1,8 @@ require_relative "../helpers" self.extend Helpers +apply "#{__dir__}/../install.rb" + say "Install Bootstrap with Bootstrap Icons, Popperjs/core and Autoprefixer" copy_file "#{__dir__}/application.bootstrap.scss", "app/assets/stylesheets/application.bootstrap.scss" diff --git a/lib/install/bulma/install.rb b/lib/install/bulma/install.rb index c5276d0..a6de35a 100644 --- a/lib/install/bulma/install.rb +++ b/lib/install/bulma/install.rb @@ -1,6 +1,8 @@ require_relative "../helpers" self.extend Helpers +apply "#{__dir__}/../install.rb" + say "Install Bulma" copy_file "#{__dir__}/application.bulma.scss", "app/assets/stylesheets/application.bulma.scss" diff --git a/lib/install/postcss/install.rb b/lib/install/postcss/install.rb index d9eb5bd..e80280b 100644 --- a/lib/install/postcss/install.rb +++ b/lib/install/postcss/install.rb @@ -1,6 +1,8 @@ require_relative "../helpers" self.extend Helpers +apply "#{__dir__}/../install.rb" + say "Install PostCSS w/ nesting and autoprefixer" copy_file "#{__dir__}/postcss.config.js", "postcss.config.js" copy_file "#{__dir__}/application.postcss.css", "app/assets/stylesheets/application.postcss.css" diff --git a/lib/install/sass/install.rb b/lib/install/sass/install.rb index 692d60e..b05a8e5 100644 --- a/lib/install/sass/install.rb +++ b/lib/install/sass/install.rb @@ -1,6 +1,8 @@ require_relative "../helpers" self.extend Helpers +apply "#{__dir__}/../install.rb" + say "Install Sass" copy_file "#{__dir__}/application.sass.scss", "app/assets/stylesheets/application.sass.scss" run "#{bundler_cmd} add sass" diff --git a/lib/install/tailwind/install.rb b/lib/install/tailwind/install.rb index 7374ff4..f8e530d 100644 --- a/lib/install/tailwind/install.rb +++ b/lib/install/tailwind/install.rb @@ -1,6 +1,8 @@ require_relative "../helpers" self.extend Helpers +apply "#{__dir__}/../install.rb" + say "Install Tailwind (+PostCSS w/ autoprefixer)" copy_file "#{__dir__}/tailwind.config.js", "tailwind.config.js" copy_file "#{__dir__}/application.tailwind.css", "app/assets/stylesheets/application.tailwind.css" diff --git a/lib/tasks/cssbundling/install.rake b/lib/tasks/cssbundling/install.rake index d093d8d..ba1df4c 100644 --- a/lib/tasks/cssbundling/install.rake +++ b/lib/tasks/cssbundling/install.rake @@ -1,32 +1,27 @@ namespace :css do namespace :install do - desc "Install shared elements for all bundlers" - task :shared do - system "#{RbConfig.ruby} ./bin/rails app:template LOCATION=#{File.expand_path("../../install/install.rb", __dir__)}" - end - desc "Install Tailwind" - task tailwind: "css:install:shared" do + task :tailwind do system "#{RbConfig.ruby} ./bin/rails app:template LOCATION=#{File.expand_path("../../install/tailwind/install.rb", __dir__)}" end desc "Install PostCSS" - task postcss: "css:install:shared" do + task :postcss do system "#{RbConfig.ruby} ./bin/rails app:template LOCATION=#{File.expand_path("../../install/postcss/install.rb", __dir__)}" end desc "Install Sass" - task sass: "css:install:shared" do + task :sass do system "#{RbConfig.ruby} ./bin/rails app:template LOCATION=#{File.expand_path("../../install/sass/install.rb", __dir__)}" end desc "Install Bootstrap" - task bootstrap: "css:install:shared" do + task :bootstrap do system "#{RbConfig.ruby} ./bin/rails app:template LOCATION=#{File.expand_path("../../install/bootstrap/install.rb", __dir__)}" end desc "Install Bulma" - task bulma: "css:install:shared" do + task :bulma do system "#{RbConfig.ruby} ./bin/rails app:template LOCATION=#{File.expand_path("../../install/bulma/install.rb", __dir__)}" end end