Skip to content

Commit

Permalink
Merge pull request #132 from excid3/build-command-namespace
Browse files Browse the repository at this point in the history
Namespace helper methods for css:build command
  • Loading branch information
rafaelfranca authored Sep 13, 2023
2 parents 2f2945e + 614ef52 commit 2b2d984
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions lib/tasks/cssbundling/build.rake
Original file line number Diff line number Diff line change
@@ -1,36 +1,42 @@
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
end

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
end
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"]
Expand Down

0 comments on commit 2b2d984

Please sign in to comment.