diff --git a/lib/tasks/cssbundling/build.rake b/lib/tasks/cssbundling/build.rake index 90033e2..dcdd429 100644 --- a/lib/tasks/cssbundling/build.rake +++ b/lib/tasks/cssbundling/build.rake @@ -1,7 +1,7 @@ namespace :css do desc "Install JavaScript dependencies" task :install do - command = install_command + command = Cssbundling::Tasks.install_command unless system(command) raise "cssbundling-rails: Command install failed, ensure #{command.split.first} is installed" end @@ -9,7 +9,7 @@ namespace :css do desc "Build your CSS bundle" build_task = task :build do - command = build_command + command = Cssbundling::Tasks.build_command unless system(command) raise "cssbundling-rails: Command build failed, ensure `#{command}` runs without errors" end @@ -17,20 +17,26 @@ namespace :css do build_task.prereqs << :install unless ENV["SKIP_YARN_INSTALL"] || ENV["SKIP_BUN_INSTALL"] end -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" -end +module Cssbundling + module Tasks + extend self -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" -end + 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" + end -def tool_exists?(tool) - system "command -v #{tool} > /dev/null" + 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" + end + + def tool_exists?(tool) + system "command -v #{tool} > /dev/null" + end + end end unless ENV["SKIP_CSS_BUILD"]