@@ -23,22 +23,37 @@ module Jsbundling
2323 extend self
2424
2525 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
3032 end
3133
3234 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
3741 end
3842
3943 def tool_exists? ( tool )
4044 system "command -v #{ tool } > /dev/null"
4145 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
4257 end
4358end
4459
0 commit comments