@@ -23,22 +23,37 @@ module Jsbundling
23
23
extend self
24
24
25
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' ) && !File . exist? ( 'package-lock.json' ) )
28
- return "npm install" if File . exist? ( 'package-lock.json' ) || tool_exists? ( 'npm' )
29
- raise "jsbundling-rails: No suitable tool found for installing JavaScript dependencies"
26
+ case tool
27
+ when :bun then "bun install"
28
+ when :yarn then "yarn install"
29
+ when :npm then "npm install"
30
+ else raise "jsbundling-rails: No suitable tool found for installing JavaScript dependencies"
31
+ end
30
32
end
31
33
32
34
def build_command
33
- return "bun run build" if File . exist? ( 'bun.lockb' ) || ( tool_exists? ( 'bun' ) && !File . exist? ( 'yarn.lock' ) )
34
- return "yarn build" if File . exist? ( 'yarn.lock' ) || ( tool_exists? ( 'yarn' ) && !File . exist? ( 'package-lock.json' ) )
35
- return "npm run build" if File . exist? ( 'package-lock.json' ) || tool_exists? ( 'npm' )
36
- raise "jsbundling-rails: No suitable tool found for building JavaScript"
35
+ case tool
36
+ when :bun then "bun run build"
37
+ when :yarn then "yarn build"
38
+ when :npm then "npm run build"
39
+ else raise "jsbundling-rails: No suitable tool found for building JavaScript"
40
+ end
37
41
end
38
42
39
43
def tool_exists? ( tool )
40
44
system "command -v #{ tool } > /dev/null"
41
45
end
46
+
47
+ def tool
48
+ case
49
+ when File . exist? ( 'bun.lockb' ) then :bun
50
+ when File . exist? ( 'yarn.lock' ) then :yarn
51
+ when File . exist? ( 'package-lock.json' ) then :npm
52
+ when tool_exists? ( 'bun' ) then :bun
53
+ when tool_exists? ( 'yarn' ) then :yarn
54
+ when tool_exists? ( 'npm' ) then :npm
55
+ end
56
+ end
42
57
end
43
58
end
44
59
0 commit comments