diff --git a/lib/tasks/cssbundling/build.rake b/lib/tasks/cssbundling/build.rake index dcdd429..2682b23 100644 --- a/lib/tasks/cssbundling/build.rake +++ b/lib/tasks/cssbundling/build.rake @@ -22,15 +22,32 @@ module Cssbundling extend self def install_command - return "bun install" if File.exist?('bun.lockb') || (tool_exists?('bun') && !File.exist?('yarn.lock')) - return "yarn install" if File.exist?('yarn.lock') || tool_exists?('yarn') - raise "cssbundling-rails: No suitable tool found for installing JavaScript dependencies" + case tool + when :bun then "bun install" + when :yarn then "yarn install" + when :npm then "npm install" + else raise "cssbundling-rails: No suitable tool found for installing JavaScript dependencies" + end end def build_command - return "bun run build:css" if File.exist?('bun.lockb') || (tool_exists?('bun') && !File.exist?('yarn.lock')) - return "yarn build:css" if File.exist?('yarn.lock') || tool_exists?('yarn') - raise "cssbundling-rails: No suitable tool found for building CSS" + case tool + when :bun then "bun run build:css" + when :yarn then "yarn build:css" + when :npm then "npm run build:css" + else raise "cssbundling-rails: No suitable tool found for building CSS" + end + end + + def tool + case + when File.exist?('bun.lockb') then :bun + when File.exist?('yarn.lock') then :yarn + when File.exist?('package-lock.json') then :npm + when tool_exists?('bun') then :bun + when tool_exists?('yarn') then :yarn + when tool_exists?('npm') then :npm + end end def tool_exists?(tool)