Skip to content

Commit 4bce06b

Browse files
Use Thor's apply instead of prerequisite tasks (#183)
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.
1 parent 0afb806 commit 4bce06b

File tree

6 files changed

+15
-14
lines changed

6 files changed

+15
-14
lines changed

lib/install/bun/install.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
require 'json'
22

3+
apply "#{__dir__}/../install.rb"
4+
35
if Rails.root.join("Procfile.dev").exist?
46
append_to_file "Procfile.dev", "js: bun run build --watch\n"
57
else

lib/install/esbuild/install.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
apply "#{__dir__}/../install.rb"
2+
apply "#{__dir__}/../install_procfile.rb"
3+
14
say "Install esbuild"
25
run "yarn add esbuild"
36

File renamed without changes.

lib/install/rollup/install.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
apply "#{__dir__}/../install.rb"
2+
apply "#{__dir__}/../install_procfile.rb"
3+
14
say "Install rollup with config"
25
copy_file "#{__dir__}/rollup.config.js", "rollup.config.js"
36
run "yarn add rollup @rollup/plugin-node-resolve"

lib/install/webpack/install.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
apply "#{__dir__}/../install.rb"
2+
apply "#{__dir__}/../install_procfile.rb"
3+
14
say "Install Webpack with config"
25
copy_file "#{__dir__}/webpack.config.js", "webpack.config.js"
36
run "yarn add webpack webpack-cli"

lib/tasks/jsbundling/install.rake

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,22 @@
11
namespace :javascript do
22
namespace :install do
3-
desc "Install shared elements for all bundlers"
4-
task :shared do
5-
system "#{RbConfig.ruby} ./bin/rails app:template LOCATION=#{File.expand_path("../../install/install.rb", __dir__)}"
6-
end
7-
8-
desc "Install node-specific elements for bundlers that use node/yarn."
9-
task :node_shared do
10-
system "#{RbConfig.ruby} ./bin/rails app:template LOCATION=#{File.expand_path("../../install/install_node.rb", __dir__)}"
11-
end
12-
133
desc "Install Bun"
14-
task bun: "javascript:install:shared" do
4+
task :bun do
155
system "#{RbConfig.ruby} ./bin/rails app:template LOCATION=#{File.expand_path("../../install/bun/install.rb", __dir__)}"
166
end
177

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

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

2818
desc "Install Webpack"
29-
task webpack: ["javascript:install:shared", "javascript:install:node_shared"] do
19+
task :webpack do
3020
system "#{RbConfig.ruby} ./bin/rails app:template LOCATION=#{File.expand_path("../../install/webpack/install.rb", __dir__)}"
3121
end
3222
end

0 commit comments

Comments
 (0)