Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Namespace helper methods for css:build command #132

Merged
merged 1 commit into from
Sep 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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