Skip to content

Commit 8f308f4

Browse files
committed
Import all the relevant files, rake tasks, and tests
from tailwindcss-rails. Update them as needed with constant names, paths, etc.
1 parent 7ea3c59 commit 8f308f4

File tree

12 files changed

+565
-45
lines changed

12 files changed

+565
-45
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
/_yardoc/
44
/coverage/
55
/doc/
6+
/exe/*/tailwindcss
67
/pkg/
78
/spec/reports/
89
/tmp/

CHANGELOG.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
## [Unreleased]
22

3-
## [0.1.0] - 2024-09-25
3+
## first / unreleased
44

5-
- Initial release
5+
* This gem was extracted from `tailwindcss-rails`.
6+
7+
In advance of the upcoming TailwindCSS v4 release, we are decoupling the `tailwindcss` executable
8+
from the Rails integration. This will allow users to upgrade TailwindCSS at a time of their
9+
choosing, and allow early adopters to start using the beta releases.
10+
11+
It should also make it easier for non-Rails Ruby projects to use tailwindcss (e.g., Jekyll and other web frameworks).

CONTRIBUTING.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Contributing to tailwindcss-ruby
2+
3+
This doc is a brief introduction on modifying and maintaining this gem.
4+
5+
## Updating to the latest upstream tailwindcss version
6+
7+
Update `lib/tailwindcss/ruby/upstream.rb` with the upstream version.
8+
9+
Run `bundle exec rake clobber` then `bundle exec rake download` to ensure the tailwindcss binaries can be downloaded, and that you have the correct versions on local disk.
10+
11+
## Cutting a release of tailwindcss-ruby
12+
13+
- bump the version
14+
- [ ] update `lib/tailwindcss/ruby/version.rb`
15+
- [ ] update `CHANGELOG.md`
16+
- [ ] commit and create a git tag
17+
- build the native gems:
18+
- [ ] `bundle exec rake clobber` if needed to clean up possibly-old tailwindcss executables
19+
- [ ] `bundle exec rake package`
20+
- push
21+
- [ ] `for g in pkg/*.gem ; do gem push $g ; done`
22+
- [ ] `git push && git push --tags`
23+
- announce
24+
- [ ] create a release at https://github.com/flavorjones/tailwindcss-ruby/releases

LICENSE-DEPENDENCIES

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
tailwindcss-rails may redistribute executables from the https://github.com/tailwindlabs/tailwindcss project
2+
3+
The license for that software can be found at https://github.com/tailwindlabs/tailwindcss/blob/master/LICENSE which is reproduced here for your convenience:
4+
5+
MIT License
6+
7+
Copyright (c) Adam Wathan <[email protected]>
8+
Copyright (c) Jonathan Reinink <[email protected]>
9+
10+
Permission is hereby granted, free of charge, to any person obtaining a copy
11+
of this software and associated documentation files (the "Software"), to deal
12+
in the Software without restriction, including without limitation the rights
13+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14+
copies of the Software, and to permit persons to whom the Software is
15+
furnished to do so, subject to the following conditions:
16+
17+
The above copyright notice and this permission notice shall be included in all
18+
copies or substantial portions of the Software.
19+
20+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26+
SOFTWARE.

LICENSE.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2024 Mike Dalessio
3+
Copyright (c) 2020-2024 Mike Dalessio, David Heinemeier Hansson
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 125 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,148 @@
11
# Tailwindcss::Ruby
22

3-
TODO: Delete this and the text below, and describe your gem
3+
A self-contained `tailwindcss` executable, wrapped up in a ruby gem. That's it. Nothing else.
4+
5+
If you're looking to leverage tailwindcss in your Rails project, please see https://github.com/rails/tailwindcss-rails for integration that is supported by the Rails team.
46

5-
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/tailwindcss/ruby`. To experiment with that code, run `bin/console` for an interactive prompt.
67

78
## Installation
89

9-
TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
10+
This gem wraps [the standalone executable version](https://tailwindcss.com/blog/standalone-cli) of the Tailwind CSS v3 framework. These executables are platform specific, so there are actually separate underlying gems per platform, but the correct gem will automatically be picked for your platform.
11+
12+
Supported platforms are:
13+
14+
- arm64-darwin (macos-arm64)
15+
- x64-mingw32 (windows-x64)
16+
- x64-mingw-ucr (windows-x64)
17+
- x86_64-darwin (macos-x64)
18+
- x86_64-linux (linux-x64)
19+
- aarch64-linux (linux-arm64)
20+
- arm-linux (linux-armv7)
1021

1122
Install the gem and add to the application's Gemfile by executing:
1223

1324
```bash
14-
bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
25+
bundle add tailwindcss-ruby
1526
```
1627

1728
If bundler is not being used to manage dependencies, install the gem by executing:
1829

1930
```bash
20-
gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
31+
gem install tailwindcss-ruby
32+
```
33+
34+
### Using a local installation of `tailwindcss`
35+
36+
If you are not able to use the vendored standalone executables (for example, if you're on an unsupported platform), you can use a local installation of the `tailwindcss` executable by setting an environment variable named `TAILWINDCSS_INSTALL_DIR` to the directory path containing the executable.
37+
38+
For example, if you've installed `tailwindcss` so that the executable is found at `/path/to/node_modules/bin/tailwindcss`, then you should set your environment variable like so:
39+
40+
``` sh
41+
TAILWINDCSS_INSTALL_DIR=/path/to/node_modules/bin
42+
```
43+
44+
or, for relative paths like `./node_modules/.bin/tailwindcss`:
45+
46+
``` sh
47+
TAILWINDCSS_INSTALL_DIR=node_modules/.bin
2148
```
2249

50+
51+
## Versioning
52+
53+
This gem will always have the same version number as the underlying TailwindCSS release. For example, the gem with version v3.4.13 will package upstream TailwindCSS v3.4.13.
54+
55+
If there ever needs to be multiple releases for the same version of TailwindCSS, the version will contain an additional digit. For example, if we re-released TailwindCSS v3.4.13, it might be shipped in gem version v3.4.13.1 or v3.4.13.2.
56+
57+
2358
## Usage
2459

25-
TODO: Write usage instructions here
60+
### Ruby
61+
62+
The gem makes available `Tailwindcss::Ruby.executable` which is the path to the vendored standalone executable.
63+
64+
``` ruby
65+
require "tailwindcss/ruby"
66+
Tailwindcss::Ruby.executable
67+
# => "/path/to/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/tailwindcss-ruby-0.1.0-x86_64-linux/exe/x86_64-linux/tailwindcss"
68+
```
69+
70+
71+
### Command line
72+
73+
This gem provides an executable `tailwindcss` shim that will run the vendored standalone executable.
74+
75+
``` bash
76+
# where is the shim?
77+
$ bundle exec which tailwindcss
78+
/path/to/installs/ruby/3.3/bin/tailwindcss
2679

27-
## Development
80+
# run the actual executable through the shim
81+
$ bundle exec tailwindcss --help
82+
["/path/to/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/tailwindcss-rails-2.6.0-x86_64-linux/exe/x86_64-linux/tailwindcss", "--help"]
2883

29-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
84+
tailwindcss v3.4.3
85+
86+
Usage:
87+
tailwindcss [--input input.css] [--output output.css] [--watch] [options...]
88+
tailwindcss init [--full] [--postcss] [options...]
89+
90+
Commands:
91+
init [options]
92+
93+
Options:
94+
-i, --input Input file
95+
-o, --output Output file
96+
-w, --watch Watch for changes and rebuild as needed
97+
-p, --poll Use polling instead of filesystem events when watching
98+
--content Content paths to use for removing unused classes
99+
--postcss Load custom PostCSS configuration
100+
-m, --minify Minify the output
101+
-c, --config Path to a custom config file
102+
--no-autoprefixer Disable autoprefixer
103+
-h, --help Display usage information
104+
```
105+
106+
107+
## Troubleshooting
108+
109+
### `ERROR: Cannot find the tailwindcss executable` for supported platform
110+
111+
Some users are reporting this error even when running on one of the supported native platforms:
112+
113+
- arm64-darwin
114+
- x64-mingw32
115+
- x64-mingw-ucrt
116+
- x86_64-darwin
117+
- x86_64-linux
118+
- aarch64-linux
119+
120+
#### Check Bundler PLATFORMS
121+
122+
A possible cause of this is that Bundler has not been told to include native gems for your current platform. Please check your `Gemfile.lock` file to see whether your native platform is included in the `PLATFORMS` section. If necessary, run:
123+
124+
``` sh
125+
bundle lock --add-platform <platform-name>
126+
```
127+
128+
and re-bundle.
129+
130+
131+
#### Check BUNDLE_FORCE_RUBY_PLATFORM
132+
133+
Another common cause of this is that bundler is configured to always use the "ruby" platform via the
134+
`BUNDLE_FORCE_RUBY_PLATFORM` config parameter being set to `true`. Please remove this configuration:
135+
136+
``` sh
137+
bundle config unset force_ruby_platform
138+
# or
139+
bundle config set --local force_ruby_platform false
140+
```
141+
142+
and re-bundle.
143+
144+
See https://bundler.io/man/bundle-config.1.html for more information.
30145

31-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32146

33147
## Contributing
34148

@@ -38,6 +152,8 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/flavor
38152

39153
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
40154

155+
Tailwind CSS is [released under the MIT License](https://github.com/tailwindlabs/tailwindcss/blob/next/LICENSE).
156+
41157
## Code of Conduct
42158

43159
Everyone interacting in the Tailwindcss::Ruby project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/flavorjones/tailwindcss-ruby/blob/main/CODE_OF_CONDUCT.md).

exe/tailwindcss

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#! /usr/bin/env ruby
2+
# because rubygems shims assume a gem's executables are Ruby
3+
4+
require "tailwindcss/commands"
5+
6+
begin
7+
command = [Tailwindcss::Ruby.executable, *ARGV]
8+
puts command.inspect
9+
if Gem.win_platform?
10+
# use system rather than exec as exec inexplicably fails to find the executable on Windows
11+
# see related https://github.com/rubys/sprockets-esbuild/pull/4
12+
system(*command, exception: true)
13+
else
14+
exec(*command)
15+
end
16+
rescue Tailwindcss::Ruby::UnsupportedPlatformException, Tailwindcss::Ruby::ExecutableNotFoundException => e
17+
STDERR.puts("ERROR: " + e.message)
18+
exit 1
19+
end

lib/tailwindcss/ruby.rb

Lines changed: 72 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,80 @@
11
# frozen_string_literal: true
22

33
require_relative "ruby/version"
4+
require_relative "ruby/upstream"
45

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

lib/tailwindcss/ruby/upstream.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module Tailwindcss
2+
module Ruby
3+
module Upstream
4+
VERSION = "v3.4.13"
5+
6+
# rubygems platform name => upstream release filename
7+
NATIVE_PLATFORMS = {
8+
"arm64-darwin" => "tailwindcss-macos-arm64",
9+
"x64-mingw32" => "tailwindcss-windows-x64.exe",
10+
"x64-mingw-ucrt" => "tailwindcss-windows-x64.exe",
11+
"x86_64-darwin" => "tailwindcss-macos-x64",
12+
"x86_64-linux" => "tailwindcss-linux-x64",
13+
"aarch64-linux" => "tailwindcss-linux-arm64",
14+
"arm-linux" => "tailwindcss-linux-armv7",
15+
}
16+
end
17+
end
18+
end

0 commit comments

Comments
 (0)