|
1 | 1 | namespace :css do
|
2 | 2 | desc "Install JavaScript dependencies"
|
3 | 3 | task :install do
|
4 |
| - command = install_command |
| 4 | + command = Cssbundling::Tasks.install_command |
5 | 5 | unless system(command)
|
6 | 6 | raise "cssbundling-rails: Command install failed, ensure #{command.split.first} is installed"
|
7 | 7 | end
|
8 | 8 | end
|
9 | 9 |
|
10 | 10 | desc "Build your CSS bundle"
|
11 | 11 | build_task = task :build do
|
12 |
| - command = build_command |
| 12 | + command = Cssbundling::Tasks.build_command |
13 | 13 | unless system(command)
|
14 | 14 | raise "cssbundling-rails: Command build failed, ensure `#{command}` runs without errors"
|
15 | 15 | end
|
16 | 16 | end
|
17 | 17 | build_task.prereqs << :install unless ENV["SKIP_YARN_INSTALL"] || ENV["SKIP_BUN_INSTALL"]
|
18 | 18 | end
|
19 | 19 |
|
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 |
25 | 23 |
|
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 |
31 | 29 |
|
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 |
34 | 40 | end
|
35 | 41 |
|
36 | 42 | unless ENV["SKIP_CSS_BUILD"]
|
|
0 commit comments