Skip to content

Commit

Permalink
Use Thor's apply instead of prerequisite tasks (#183)
Browse files Browse the repository at this point in the history
The `javascript:install:shared` and `javascript:install:node_shared`
tasks serve only as prerequisites for the other installer tasks; they
should not be run on their own (nor listed with `rake --tasks`).  By
replacing those tasks with corresponding calls to Thor's `apply` method,
we avoid the overhead of running `bin/rails app:template` (and
`bundle install`) multiple times.

This commit also renames `install_node.rb` to `install_procfile.rb`
since it is concerned with generating a `Procfile.dev` file.
  • Loading branch information
jonathanhefner committed Jan 21, 2024
1 parent 0afb806 commit 4bce06b
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 14 deletions.
2 changes: 2 additions & 0 deletions lib/install/bun/install.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
require 'json'

apply "#{__dir__}/../install.rb"

if Rails.root.join("Procfile.dev").exist?
append_to_file "Procfile.dev", "js: bun run build --watch\n"
else
Expand Down
3 changes: 3 additions & 0 deletions lib/install/esbuild/install.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
apply "#{__dir__}/../install.rb"
apply "#{__dir__}/../install_procfile.rb"

say "Install esbuild"
run "yarn add esbuild"

Expand Down
File renamed without changes.
3 changes: 3 additions & 0 deletions lib/install/rollup/install.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
apply "#{__dir__}/../install.rb"
apply "#{__dir__}/../install_procfile.rb"

say "Install rollup with config"
copy_file "#{__dir__}/rollup.config.js", "rollup.config.js"
run "yarn add rollup @rollup/plugin-node-resolve"
Expand Down
3 changes: 3 additions & 0 deletions lib/install/webpack/install.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
apply "#{__dir__}/../install.rb"
apply "#{__dir__}/../install_procfile.rb"

say "Install Webpack with config"
copy_file "#{__dir__}/webpack.config.js", "webpack.config.js"
run "yarn add webpack webpack-cli"
Expand Down
18 changes: 4 additions & 14 deletions lib/tasks/jsbundling/install.rake
Original file line number Diff line number Diff line change
@@ -1,32 +1,22 @@
namespace :javascript 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 node-specific elements for bundlers that use node/yarn."
task :node_shared do
system "#{RbConfig.ruby} ./bin/rails app:template LOCATION=#{File.expand_path("../../install/install_node.rb", __dir__)}"
end

desc "Install Bun"
task bun: "javascript:install:shared" do
task :bun do
system "#{RbConfig.ruby} ./bin/rails app:template LOCATION=#{File.expand_path("../../install/bun/install.rb", __dir__)}"
end

desc "Install esbuild"
task esbuild: ["javascript:install:shared", "javascript:install:node_shared"] do
task :esbuild do
system "#{RbConfig.ruby} ./bin/rails app:template LOCATION=#{File.expand_path("../../install/esbuild/install.rb", __dir__)}"
end

desc "Install rollup.js"
task rollup: ["javascript:install:shared", "javascript:install:node_shared"] do
task :rollup do
system "#{RbConfig.ruby} ./bin/rails app:template LOCATION=#{File.expand_path("../../install/rollup/install.rb", __dir__)}"
end

desc "Install Webpack"
task webpack: ["javascript:install:shared", "javascript:install:node_shared"] do
task :webpack do
system "#{RbConfig.ruby} ./bin/rails app:template LOCATION=#{File.expand_path("../../install/webpack/install.rb", __dir__)}"
end
end
Expand Down

0 comments on commit 4bce06b

Please sign in to comment.