Skip to content

Commit ccd3017

Browse files
authored
Merge pull request #172 from excid3/build-tasks-namespace
Namespace helper methods for javascript:build tasks
2 parents 4006cb7 + 51e5b81 commit ccd3017

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

lib/tasks/jsbundling/build.rake

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
namespace :javascript do
22
desc "Install JavaScript dependencies"
33
task :install do
4-
command = install_command
4+
command = Jsbundling::Tasks.install_command
55
unless system(command)
66
raise "jsbundling-rails: Command install failed, ensure #{command.split.first} is installed"
77
end
88
end
99

1010
desc "Build your JavaScript bundle"
1111
build_task = task :build do
12-
command = build_command
12+
command = Jsbundling::Tasks.build_command
1313
unless system(command)
1414
raise "jsbundling-rails: Command build failed, ensure `#{command}` runs without errors"
1515
end
@@ -18,20 +18,26 @@ namespace :javascript do
1818
build_task.prereqs << :install unless ENV["SKIP_YARN_INSTALL"] || ENV["SKIP_BUN_INSTALL"]
1919
end
2020

21-
def install_command
22-
return "bun install" if File.exist?('bun.lockb') || (tool_exists?('bun') && !File.exist?('yarn.lock'))
23-
return "yarn install" if File.exist?('yarn.lock') || tool_exists?('yarn')
24-
raise "jsbundling-rails: No suitable tool found for installing JavaScript dependencies"
25-
end
21+
module Jsbundling
22+
module Tasks
23+
extend self
2624

27-
def build_command
28-
return "bun run build" if File.exist?('bun.lockb') || (tool_exists?('bun') && !File.exist?('yarn.lock'))
29-
return "yarn build" if File.exist?('yarn.lock') || tool_exists?('yarn')
30-
raise "jsbundling-rails: No suitable tool found for building JavaScript"
31-
end
25+
def install_command
26+
return "bun install" if File.exist?('bun.lockb') || (tool_exists?('bun') && !File.exist?('yarn.lock'))
27+
return "yarn install" if File.exist?('yarn.lock') || tool_exists?('yarn')
28+
raise "jsbundling-rails: No suitable tool found for installing JavaScript dependencies"
29+
end
3230

33-
def tool_exists?(tool)
34-
system "command -v #{tool} > /dev/null"
31+
def build_command
32+
return "bun run build" if File.exist?('bun.lockb') || (tool_exists?('bun') && !File.exist?('yarn.lock'))
33+
return "yarn build" if File.exist?('yarn.lock') || tool_exists?('yarn')
34+
raise "jsbundling-rails: No suitable tool found for building JavaScript"
35+
end
36+
37+
def tool_exists?(tool)
38+
system "command -v #{tool} > /dev/null"
39+
end
40+
end
3541
end
3642

3743
unless ENV["SKIP_JS_BUILD"]

0 commit comments

Comments
 (0)