Skip to content

Commit 2b2d984

Browse files
authored
Merge pull request #132 from excid3/build-command-namespace
Namespace helper methods for css:build command
2 parents 2f2945e + 614ef52 commit 2b2d984

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

lib/tasks/cssbundling/build.rake

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,42 @@
11
namespace :css do
22
desc "Install JavaScript dependencies"
33
task :install do
4-
command = install_command
4+
command = Cssbundling::Tasks.install_command
55
unless system(command)
66
raise "cssbundling-rails: Command install failed, ensure #{command.split.first} is installed"
77
end
88
end
99

1010
desc "Build your CSS bundle"
1111
build_task = task :build do
12-
command = build_command
12+
command = Cssbundling::Tasks.build_command
1313
unless system(command)
1414
raise "cssbundling-rails: Command build failed, ensure `#{command}` runs without errors"
1515
end
1616
end
1717
build_task.prereqs << :install unless ENV["SKIP_YARN_INSTALL"] || ENV["SKIP_BUN_INSTALL"]
1818
end
1919

20-
def install_command
21-
return "bun install" if File.exist?('bun.lockb') || (tool_exists?('bun') && !File.exist?('yarn.lock'))
22-
return "yarn install" if File.exist?('yarn.lock') || tool_exists?('yarn')
23-
raise "cssbundling-rails: No suitable tool found for installing JavaScript dependencies"
24-
end
20+
module Cssbundling
21+
module Tasks
22+
extend self
2523

26-
def build_command
27-
return "bun run build:css" if File.exist?('bun.lockb') || (tool_exists?('bun') && !File.exist?('yarn.lock'))
28-
return "yarn build:css" if File.exist?('yarn.lock') || tool_exists?('yarn')
29-
raise "cssbundling-rails: No suitable tool found for building CSS"
30-
end
24+
def install_command
25+
return "bun install" if File.exist?('bun.lockb') || (tool_exists?('bun') && !File.exist?('yarn.lock'))
26+
return "yarn install" if File.exist?('yarn.lock') || tool_exists?('yarn')
27+
raise "cssbundling-rails: No suitable tool found for installing JavaScript dependencies"
28+
end
3129

32-
def tool_exists?(tool)
33-
system "command -v #{tool} > /dev/null"
30+
def build_command
31+
return "bun run build:css" if File.exist?('bun.lockb') || (tool_exists?('bun') && !File.exist?('yarn.lock'))
32+
return "yarn build:css" if File.exist?('yarn.lock') || tool_exists?('yarn')
33+
raise "cssbundling-rails: No suitable tool found for building CSS"
34+
end
35+
36+
def tool_exists?(tool)
37+
system "command -v #{tool} > /dev/null"
38+
end
39+
end
3440
end
3541

3642
unless ENV["SKIP_CSS_BUILD"]

0 commit comments

Comments
 (0)