Module: Tailwindcss::Ruby

Defined in:
lib/tailwindcss/ruby.rb,
lib/tailwindcss/ruby/version.rb,
lib/tailwindcss/ruby/upstream.rb

Defined Under Namespace

Modules: Upstream Classes: DirectoryNotFoundException, ExecutableNotFoundException, UnsupportedPlatformException

Constant Summary collapse

DEFAULT_DIR =
File.expand_path(File.join(__dir__, "..", "..", "exe"))
GEM_NAME =
"tailwindcss-ruby"
VERSION =
"3.4.17"

Class Method Summary collapse

Class Method Details

.executable(exe_path: DEFAULT_DIR) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/tailwindcss/ruby.rb', line 28

def executable(exe_path: DEFAULT_DIR)
  tailwindcss_install_dir = ENV["TAILWINDCSS_INSTALL_DIR"]
  if tailwindcss_install_dir
    if File.directory?(tailwindcss_install_dir)
      warn "NOTE: using TAILWINDCSS_INSTALL_DIR to find tailwindcss executable: #{tailwindcss_install_dir}"
      exe_path = tailwindcss_install_dir
      exe_file = File.expand_path(File.join(tailwindcss_install_dir, "tailwindcss"))
    else
      raise DirectoryNotFoundException, <<~MESSAGE
        TAILWINDCSS_INSTALL_DIR is set to #{tailwindcss_install_dir}, but that directory does not exist.
      MESSAGE
    end
  else
    if Tailwindcss::Ruby::Upstream::NATIVE_PLATFORMS.keys.none? { |p| Gem::Platform.match_gem?(Gem::Platform.new(p), GEM_NAME) }
      raise UnsupportedPlatformException, <<~MESSAGE
        #{GEM_NAME} does not support the #{platform} platform
        See https://github.com/flavorjones/tailwindcss-ruby#using-a-local-installation-of-tailwindcss
        for more details.
      MESSAGE
    end

    exe_file = Dir.glob(File.expand_path(File.join(exe_path, "*", "tailwindcss"))).find do |f|
      Gem::Platform.match_gem?(Gem::Platform.new(File.basename(File.dirname(f))), GEM_NAME)
    end
  end

  if exe_file.nil? || !File.exist?(exe_file)
    raise ExecutableNotFoundException, <<~MESSAGE
      Cannot find the tailwindcss executable for #{platform} in #{exe_path}

      If you're using bundler, please make sure you're on the latest bundler version:

          gem install bundler
          bundle update --bundler

      Then make sure your lock file includes this platform by running:

          bundle lock --add-platform #{platform}
          bundle install

      See `bundle lock --help` output for details.

      If you're still seeing this message after taking those steps, try running
      `bundle config` and ensure `force_ruby_platform` isn't set to `true`. See
      https://github.com/flavorjones/tailwindcss-ruby#check-bundle_force_ruby_platform
      for more details.
    MESSAGE
  end

  exe_file
end

.platformObject



24
25
26
# File 'lib/tailwindcss/ruby.rb', line 24

def platform
  [:cpu, :os].map { |m| Gem::Platform.local.send(m) }.join("-")
end