Skip to content

Commit 7866a7b

Browse files
Styles Generator: Drop support for Tailwind (#1169)
Follow-up to #1145 and #1148 We decided it's best to limit the decisions a consumer needs to make. Even though we defaulted to PostCSS, providing an option to override this value felt like it went against the Suspenders ethos. Additionally, the current version of Suspenders uses PostCSS, so this change aligns with current behavior. Also removes linting rules around Tailwind.
1 parent 8b8ecb9 commit 7866a7b

File tree

8 files changed

+13
-212
lines changed

8 files changed

+13
-212
lines changed

README.md

+3-6
Original file line numberDiff line numberDiff line change
@@ -94,16 +94,13 @@ via [better_html][], [erb_lint][] and [erblint-github][].
9494

9595
### Styles
9696

97-
Configures applications to use [PostCSS][] or [Tailwind][] via
98-
[cssbundling-rails][]. Defaults to PostCSS with [modern-normalize][], with the
99-
option to override via `--css=tailwind`.
97+
Configures applications to use [PostCSS][] via [cssbundling-rails][].
10098

101-
Also creates additional stylesheets if using PostCSS.
99+
Adds [modern-normalize][], and style sheet structure.
102100

103-
`bin/rails g suspenders:styles --css[postcss:tailwind]`
101+
`bin/rails g suspenders:styles`
104102

105103
[PostCSS]: https://postcss.org
106-
[Tailwind]: https://tailwindcss.com
107104
[cssbundling-rails]: https://github.com/rails/cssbundling-rails
108105
[modern-normalize]: https://github.com/sindresorhus/modern-normalize
109106

lib/generators/suspenders/lint_generator.rb

+1-5
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,7 @@ def install_gems
2121
end
2222

2323
def configure_stylelint
24-
if using_tailwind?
25-
copy_file "tailwind.stylelintrc.json", ".stylelintrc.json"
26-
else
27-
copy_file "stylelintrc.json", ".stylelintrc.json"
28-
end
24+
copy_file "stylelintrc.json", ".stylelintrc.json"
2925
end
3026

3127
def configure_eslint

lib/generators/suspenders/styles_generator.rb

+3-23
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,20 @@ module Generators
33
class StylesGenerator < Rails::Generators::Base
44
include Suspenders::Generators::APIAppUnsupported
55

6-
CSS_OPTIONS = %w[tailwind postcss].freeze
7-
8-
class_option :css, enum: CSS_OPTIONS, default: "postcss"
96
desc <<~TEXT
10-
Configures applications to use PostCSS or Tailwind via cssbundling-rails.
11-
Defaults to PostCSS with modern-normalize, with the option to override via
12-
--css=tailwind.
7+
Configures application to use PostCSS via cssbundling-rails.
138
14-
Also creates additional stylesheets if using PostCSS.
9+
Adds modern-normalize, and style sheet structure.
1510
TEXT
1611

1712
def add_cssbundling_rails_gem
1813
gem "cssbundling-rails"
1914

2015
Bundler.with_unbundled_env { run "bundle install" }
21-
run "bin/rails css:install:#{css}"
16+
run "bin/rails css:install:postcss"
2217
end
2318

2419
def build_directory_structure
25-
return if is_tailwind?
26-
2720
create_file "app/assets/stylesheets/base.css"
2821
append_to_file "app/assets/stylesheets/base.css", "/* Base Styles */"
2922

@@ -34,10 +27,7 @@ def build_directory_structure
3427
append_to_file "app/assets/stylesheets/utilities.css", "/* Utility Styles */"
3528
end
3629

37-
# Modify if https://github.com/rails/cssbundling-rails/pull/139 is merged
3830
def configure_application_stylesheet
39-
return if is_tailwind?
40-
4131
run "yarn add modern-normalize"
4232

4333
append_to_file "app/assets/stylesheets/application.postcss.css" do
@@ -49,16 +39,6 @@ def configure_application_stylesheet
4939
TEXT
5040
end
5141
end
52-
53-
private
54-
55-
def css
56-
@css ||= options["css"]
57-
end
58-
59-
def is_tailwind?
60-
css == "tailwind"
61-
end
6242
end
6343
end
6444
end

lib/generators/templates/lint/tailwind.stylelintrc.json

-11
This file was deleted.

lib/suspenders/generators.rb

-4
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@ def default_test_helper_present?
1818
def rspec_test_helper_present?
1919
File.exist? Rails.root.join("spec/rails_helper.rb")
2020
end
21-
22-
def using_tailwind?
23-
File.exist? Rails.root.join("tailwind.config.js")
24-
end
2521
end
2622

2723
module APIAppUnsupported

test/generators/suspenders/lint_generator_test.rb

-24
Original file line numberDiff line numberDiff line change
@@ -53,30 +53,6 @@ class LintGeneratorTest < Rails::Generators::TestCase
5353
end
5454
end
5555

56-
test "configures stylelint for tailwind" do
57-
expected_content = <<~TEXT
58-
{
59-
"extends": "@thoughtbot/stylelint-config",
60-
"rules": {
61-
"scss/at-rule-no-unknown": [
62-
true,
63-
{
64-
"ignoreAtRules": ["tailwind"]
65-
}
66-
]
67-
}
68-
}
69-
TEXT
70-
71-
with_css_option :tailwind do
72-
capture(:stderr) { run_generator }
73-
74-
assert_file app_root(".stylelintrc.json") do |file|
75-
assert_equal expected_content, file
76-
end
77-
end
78-
end
79-
8056
test "configures eslint" do
8157
expected_content = <<~JSON
8258
{

test/generators/suspenders/styles_generator_test.rb

+6-124
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
module Suspenders
55
module Generators
6-
class StylesGenerator::DefaultTest < Rails::Generators::TestCase
6+
class StylesGeneratorTest < Rails::Generators::TestCase
77
include Suspenders::TestHelpers
88

99
tests Suspenders::Generators::StylesGenerator
@@ -45,130 +45,8 @@ class StylesGenerator::DefaultTest < Rails::Generators::TestCase
4545
assert_match(/bin\/rails css:install:postcss/, output)
4646
end
4747

48-
test "generator has a description" do
49-
description = <<~TEXT
50-
Configures applications to use PostCSS or Tailwind via cssbundling-rails.
51-
Defaults to PostCSS with modern-normalize, with the option to override via
52-
--css=tailwind.
53-
54-
Also creates additional stylesheets if using PostCSS.
55-
TEXT
56-
57-
assert_equal description, generator_class.desc
58-
end
59-
60-
private
61-
62-
def prepare_destination
63-
touch "Gemfile"
64-
touch "app/assets/stylesheets/application.postcss.css"
65-
end
66-
67-
def restore_destination
68-
remove_file_if_exists "Gemfile"
69-
remove_file_if_exists "package.json", root: true
70-
remove_file_if_exists "yarn.lock", root: true
71-
remove_file_if_exists "app/assets/stylesheets/application.postcss.css"
72-
remove_file_if_exists "app/assets/stylesheets/base.css"
73-
remove_file_if_exists "app/assets/stylesheets/components.css"
74-
remove_file_if_exists "app/assets/stylesheets/utilities.css"
75-
end
76-
end
77-
78-
class StylesGenerator::ClassOptionTest < Rails::Generators::TestCase
79-
include Suspenders::TestHelpers
80-
81-
tests Suspenders::Generators::StylesGenerator
82-
destination Rails.root
83-
setup :prepare_destination
84-
teardown :restore_destination
85-
86-
test "has a css option" do
87-
option = generator_class.class_options[:css]
88-
89-
assert_equal :string, option.type
90-
assert_not option.required
91-
assert_equal %w[tailwind postcss], option.enum
92-
assert_equal "postcss", option.default
93-
end
94-
95-
test "raises if css option is unsupported" do
96-
output = capture(:stderr) { run_generator %w[--css=unknown] }
97-
98-
assert_match(/Expected '--css' to be one of/, output)
99-
end
100-
101-
private
102-
103-
def prepare_destination
104-
touch "Gemfile"
105-
end
106-
107-
def restore_destination
108-
remove_file_if_exists "Gemfile"
109-
remove_file_if_exists "package.json", root: true
110-
remove_file_if_exists "yarn.lock", root: true
111-
remove_file_if_exists "app/assets/stylesheets/application.postcss.css"
112-
remove_file_if_exists "app/assets/stylesheets/base.css"
113-
remove_file_if_exists "app/assets/stylesheets/components.css"
114-
remove_file_if_exists "app/assets/stylesheets/utilities.css"
115-
end
116-
end
117-
118-
class StylesGenerator::TailwindTest < Rails::Generators::TestCase
119-
include Suspenders::TestHelpers
120-
121-
tests Suspenders::Generators::StylesGenerator
122-
destination Rails.root
123-
setup :prepare_destination
124-
teardown :restore_destination
125-
126-
test "runs install script" do
127-
output = run_generator %w[--css=tailwind]
128-
129-
assert_match(/bin\/rails css:install:tailwind/, output)
130-
end
131-
132-
test "does not install modern-normalize" do
133-
output = run_generator %w[--css=tailwind]
134-
135-
assert_no_match(/add.*modern-normalize/, output)
136-
end
137-
138-
test "does not create stylesheets" do
139-
run_generator %w[--css=tailwind]
140-
141-
assert_no_file app_root("app/assets/stylesheets/base.css")
142-
assert_no_file app_root("app/assets/stylesheets/components.css")
143-
assert_no_file app_root("app/assets/stylesheets/utilities.css")
144-
end
145-
146-
private
147-
148-
def prepare_destination
149-
touch "Gemfile"
150-
end
151-
152-
def restore_destination
153-
remove_file_if_exists "Gemfile"
154-
remove_file_if_exists "package.json", root: true
155-
remove_file_if_exists "yarn.lock", root: true
156-
remove_file_if_exists "app/assets/stylesheets/base.css"
157-
remove_file_if_exists "app/assets/stylesheets/components.css"
158-
remove_file_if_exists "app/assets/stylesheets/utilities.css"
159-
end
160-
end
161-
162-
class StylesGenerator::PostCssTest < Rails::Generators::TestCase
163-
include Suspenders::TestHelpers
164-
165-
tests Suspenders::Generators::StylesGenerator
166-
destination Rails.root
167-
setup :prepare_destination
168-
teardown :restore_destination
169-
17048
test "installs modern-normalize and imports stylesheets" do
171-
output = run_generator %w[--css=postcss]
49+
output = run_generator
17250
application_stylesheet = <<~TEXT
17351
@import "modern-normalize";
17452
@import "base.css";
@@ -197,6 +75,10 @@ class StylesGenerator::PostCssTest < Rails::Generators::TestCase
19775
end
19876
end
19977

78+
test "generator has a custom description" do
79+
assert_no_match(/Description/, generator_class.desc)
80+
end
81+
20082
private
20183

20284
def prepare_destination

test/test_helper.rb

-15
Original file line numberDiff line numberDiff line change
@@ -100,21 +100,6 @@ def with_test_suite(test_suite, &block)
100100
remove_dir_if_exists "spec"
101101
end
102102

103-
def with_css_option(css, &block)
104-
case css
105-
when :postcss
106-
touch "postcss.config.js"
107-
when :tailwind
108-
touch "tailwind.config.js"
109-
else
110-
raise ArgumentError, "unknown css option: #{css.inspect}"
111-
end
112-
yield
113-
ensure
114-
remove_file_if_exists "postcss.config.js"
115-
remove_file_if_exists "tailwind.config.js"
116-
end
117-
118103
def backup_file(file)
119104
FileUtils.copy app_root(file), app_root("#{file}.bak")
120105
end

0 commit comments

Comments
 (0)