1
1
namespace :javascript do
2
2
desc "Install JavaScript dependencies"
3
3
task :install do
4
- command = install_command
4
+ command = Jsbundling :: Tasks . install_command
5
5
unless system ( command )
6
6
raise "jsbundling-rails: Command install failed, ensure #{ command . split . first } is installed"
7
7
end
8
8
end
9
9
10
10
desc "Build your JavaScript bundle"
11
11
build_task = task :build do
12
- command = build_command
12
+ command = Jsbundling :: Tasks . build_command
13
13
unless system ( command )
14
14
raise "jsbundling-rails: Command build failed, ensure `#{ command } ` runs without errors"
15
15
end
@@ -18,20 +18,26 @@ namespace :javascript do
18
18
build_task . prereqs << :install unless ENV [ "SKIP_YARN_INSTALL" ] || ENV [ "SKIP_BUN_INSTALL" ]
19
19
end
20
20
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
26
24
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
32
30
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
35
41
end
36
42
37
43
unless ENV [ "SKIP_JS_BUILD" ]
0 commit comments