|
1 | | -require_relative "upstream" |
| 1 | +require "tailwindcss/ruby" |
2 | 2 |
|
3 | 3 | module Tailwindcss |
4 | 4 | module Commands |
5 | | - DEFAULT_DIR = File.expand_path(File.join(__dir__, "..", "..", "exe")) |
6 | | - GEM_NAME = "tailwindcss-rails" |
7 | | - |
8 | | - # raised when the host platform is not supported by upstream tailwindcss's binary releases |
9 | | - class UnsupportedPlatformException < StandardError |
10 | | - end |
11 | | - |
12 | | - # raised when the tailwindcss executable could not be found where we expected it to be |
13 | | - class ExecutableNotFoundException < StandardError |
14 | | - end |
15 | | - |
16 | | - # raised when TAILWINDCSS_INSTALL_DIR does not exist |
17 | | - class DirectoryNotFoundException < StandardError |
18 | | - end |
19 | | - |
20 | 5 | class << self |
21 | | - def platform |
22 | | - [:cpu, :os].map { |m| Gem::Platform.local.send(m) }.join("-") |
23 | | - end |
24 | | - |
25 | | - def executable(exe_path: DEFAULT_DIR) |
26 | | - tailwindcss_install_dir = ENV["TAILWINDCSS_INSTALL_DIR"] |
27 | | - if tailwindcss_install_dir |
28 | | - if File.directory?(tailwindcss_install_dir) |
29 | | - warn "NOTE: using TAILWINDCSS_INSTALL_DIR to find tailwindcss executable: #{tailwindcss_install_dir}" |
30 | | - exe_path = tailwindcss_install_dir |
31 | | - exe_file = File.expand_path(File.join(tailwindcss_install_dir, "tailwindcss")) |
32 | | - else |
33 | | - raise DirectoryNotFoundException, <<~MESSAGE |
34 | | - TAILWINDCSS_INSTALL_DIR is set to #{tailwindcss_install_dir}, but that directory does not exist. |
35 | | - MESSAGE |
36 | | - end |
37 | | - else |
38 | | - if Tailwindcss::Upstream::NATIVE_PLATFORMS.keys.none? { |p| Gem::Platform.match_gem?(Gem::Platform.new(p), GEM_NAME) } |
39 | | - raise UnsupportedPlatformException, <<~MESSAGE |
40 | | - tailwindcss-rails does not support the #{platform} platform |
41 | | - Please install tailwindcss following instructions at https://tailwindcss.com/docs/installation |
42 | | - MESSAGE |
43 | | - end |
44 | | - |
45 | | - exe_file = Dir.glob(File.expand_path(File.join(exe_path, "*", "tailwindcss"))).find do |f| |
46 | | - Gem::Platform.match_gem?(Gem::Platform.new(File.basename(File.dirname(f))), GEM_NAME) |
47 | | - end |
48 | | - end |
49 | | - |
50 | | - if exe_file.nil? || !File.exist?(exe_file) |
51 | | - raise ExecutableNotFoundException, <<~MESSAGE |
52 | | - Cannot find the tailwindcss executable for #{platform} in #{exe_path} |
53 | | -
|
54 | | - If you're using bundler, please make sure you're on the latest bundler version: |
55 | | -
|
56 | | - gem install bundler |
57 | | - bundle update --bundler |
58 | | -
|
59 | | - Then make sure your lock file includes this platform by running: |
60 | | -
|
61 | | - bundle lock --add-platform #{platform} |
62 | | - bundle install |
63 | | -
|
64 | | - See `bundle lock --help` output for details. |
65 | | -
|
66 | | - If you're still seeing this message after taking those steps, try running |
67 | | - `bundle config` and ensure `force_ruby_platform` isn't set to `true`. See |
68 | | - https://github.com/rails/tailwindcss-rails#check-bundle_force_ruby_platform |
69 | | - for more details. |
70 | | - MESSAGE |
71 | | - end |
72 | | - |
73 | | - exe_file |
74 | | - end |
75 | | - |
76 | 6 | def compile_command(debug: false, **kwargs) |
77 | 7 | command = [ |
78 | | - executable(**kwargs), |
| 8 | + Tailwindcss::Ruby.executable(**kwargs), |
79 | 9 | "-i", Rails.root.join("app/assets/stylesheets/application.tailwind.css").to_s, |
80 | 10 | "-o", Rails.root.join("app/assets/builds/tailwind.css").to_s, |
81 | 11 | "-c", Rails.root.join("config/tailwind.config.js").to_s, |
|
0 commit comments