diff --git a/README.md b/README.md index 78f108f20..f909dd25c 100644 --- a/README.md +++ b/README.md @@ -94,16 +94,13 @@ via [better_html][], [erb_lint][] and [erblint-github][]. ### Styles -Configures applications to use [PostCSS][] or [Tailwind][] via -[cssbundling-rails][]. Defaults to PostCSS with [modern-normalize][], with the -option to override via `--css=tailwind`. +Configures applications to use [PostCSS][] via [cssbundling-rails][]. -Also creates additional stylesheets if using PostCSS. +Adds [modern-normalize][], and style sheet structure. -`bin/rails g suspenders:styles --css[postcss:tailwind]` +`bin/rails g suspenders:styles` [PostCSS]: https://postcss.org - [Tailwind]: https://tailwindcss.com [cssbundling-rails]: https://github.com/rails/cssbundling-rails [modern-normalize]: https://github.com/sindresorhus/modern-normalize diff --git a/lib/generators/suspenders/lint_generator.rb b/lib/generators/suspenders/lint_generator.rb index 729bd53bf..bd71a5e3b 100644 --- a/lib/generators/suspenders/lint_generator.rb +++ b/lib/generators/suspenders/lint_generator.rb @@ -21,11 +21,7 @@ def install_gems end def configure_stylelint - if using_tailwind? - copy_file "tailwind.stylelintrc.json", ".stylelintrc.json" - else - copy_file "stylelintrc.json", ".stylelintrc.json" - end + copy_file "stylelintrc.json", ".stylelintrc.json" end def configure_eslint diff --git a/lib/generators/suspenders/styles_generator.rb b/lib/generators/suspenders/styles_generator.rb index a83b686ff..84220a752 100644 --- a/lib/generators/suspenders/styles_generator.rb +++ b/lib/generators/suspenders/styles_generator.rb @@ -3,27 +3,20 @@ module Generators class StylesGenerator < Rails::Generators::Base include Suspenders::Generators::APIAppUnsupported - CSS_OPTIONS = %w[tailwind postcss].freeze - - class_option :css, enum: CSS_OPTIONS, default: "postcss" desc <<~TEXT - Configures applications to use PostCSS or Tailwind via cssbundling-rails. - Defaults to PostCSS with modern-normalize, with the option to override via - --css=tailwind. + Configures application to use PostCSS via cssbundling-rails. - Also creates additional stylesheets if using PostCSS. + Adds modern-normalize, and style sheet structure. TEXT def add_cssbundling_rails_gem gem "cssbundling-rails" Bundler.with_unbundled_env { run "bundle install" } - run "bin/rails css:install:#{css}" + run "bin/rails css:install:postcss" end def build_directory_structure - return if is_tailwind? - create_file "app/assets/stylesheets/base.css" append_to_file "app/assets/stylesheets/base.css", "/* Base Styles */" @@ -34,10 +27,7 @@ def build_directory_structure append_to_file "app/assets/stylesheets/utilities.css", "/* Utility Styles */" end - # Modify if https://github.com/rails/cssbundling-rails/pull/139 is merged def configure_application_stylesheet - return if is_tailwind? - run "yarn add modern-normalize" append_to_file "app/assets/stylesheets/application.postcss.css" do @@ -49,16 +39,6 @@ def configure_application_stylesheet TEXT end end - - private - - def css - @css ||= options["css"] - end - - def is_tailwind? - css == "tailwind" - end end end end diff --git a/lib/generators/templates/lint/tailwind.stylelintrc.json b/lib/generators/templates/lint/tailwind.stylelintrc.json deleted file mode 100644 index 54d336fc6..000000000 --- a/lib/generators/templates/lint/tailwind.stylelintrc.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "extends": "@thoughtbot/stylelint-config", - "rules": { - "scss/at-rule-no-unknown": [ - true, - { - "ignoreAtRules": ["tailwind"] - } - ] - } -} diff --git a/lib/suspenders/generators.rb b/lib/suspenders/generators.rb index 553231c5a..cbefec2bf 100644 --- a/lib/suspenders/generators.rb +++ b/lib/suspenders/generators.rb @@ -18,10 +18,6 @@ def default_test_helper_present? def rspec_test_helper_present? File.exist? Rails.root.join("spec/rails_helper.rb") end - - def using_tailwind? - File.exist? Rails.root.join("tailwind.config.js") - end end module APIAppUnsupported diff --git a/test/generators/suspenders/lint_generator_test.rb b/test/generators/suspenders/lint_generator_test.rb index a9d587680..2bed402ff 100644 --- a/test/generators/suspenders/lint_generator_test.rb +++ b/test/generators/suspenders/lint_generator_test.rb @@ -53,30 +53,6 @@ class LintGeneratorTest < Rails::Generators::TestCase end end - test "configures stylelint for tailwind" do - expected_content = <<~TEXT - { - "extends": "@thoughtbot/stylelint-config", - "rules": { - "scss/at-rule-no-unknown": [ - true, - { - "ignoreAtRules": ["tailwind"] - } - ] - } - } - TEXT - - with_css_option :tailwind do - capture(:stderr) { run_generator } - - assert_file app_root(".stylelintrc.json") do |file| - assert_equal expected_content, file - end - end - end - test "configures eslint" do expected_content = <<~JSON { diff --git a/test/generators/suspenders/styles_generator_test.rb b/test/generators/suspenders/styles_generator_test.rb index 1c5f87234..684d909c4 100644 --- a/test/generators/suspenders/styles_generator_test.rb +++ b/test/generators/suspenders/styles_generator_test.rb @@ -3,7 +3,7 @@ module Suspenders module Generators - class StylesGenerator::DefaultTest < Rails::Generators::TestCase + class StylesGeneratorTest < Rails::Generators::TestCase include Suspenders::TestHelpers tests Suspenders::Generators::StylesGenerator @@ -45,130 +45,8 @@ class StylesGenerator::DefaultTest < Rails::Generators::TestCase assert_match(/bin\/rails css:install:postcss/, output) end - test "generator has a description" do - description = <<~TEXT - Configures applications to use PostCSS or Tailwind via cssbundling-rails. - Defaults to PostCSS with modern-normalize, with the option to override via - --css=tailwind. - - Also creates additional stylesheets if using PostCSS. - TEXT - - assert_equal description, generator_class.desc - end - - private - - def prepare_destination - touch "Gemfile" - touch "app/assets/stylesheets/application.postcss.css" - end - - def restore_destination - remove_file_if_exists "Gemfile" - remove_file_if_exists "package.json", root: true - remove_file_if_exists "yarn.lock", root: true - remove_file_if_exists "app/assets/stylesheets/application.postcss.css" - remove_file_if_exists "app/assets/stylesheets/base.css" - remove_file_if_exists "app/assets/stylesheets/components.css" - remove_file_if_exists "app/assets/stylesheets/utilities.css" - end - end - - class StylesGenerator::ClassOptionTest < Rails::Generators::TestCase - include Suspenders::TestHelpers - - tests Suspenders::Generators::StylesGenerator - destination Rails.root - setup :prepare_destination - teardown :restore_destination - - test "has a css option" do - option = generator_class.class_options[:css] - - assert_equal :string, option.type - assert_not option.required - assert_equal %w[tailwind postcss], option.enum - assert_equal "postcss", option.default - end - - test "raises if css option is unsupported" do - output = capture(:stderr) { run_generator %w[--css=unknown] } - - assert_match(/Expected '--css' to be one of/, output) - end - - private - - def prepare_destination - touch "Gemfile" - end - - def restore_destination - remove_file_if_exists "Gemfile" - remove_file_if_exists "package.json", root: true - remove_file_if_exists "yarn.lock", root: true - remove_file_if_exists "app/assets/stylesheets/application.postcss.css" - remove_file_if_exists "app/assets/stylesheets/base.css" - remove_file_if_exists "app/assets/stylesheets/components.css" - remove_file_if_exists "app/assets/stylesheets/utilities.css" - end - end - - class StylesGenerator::TailwindTest < Rails::Generators::TestCase - include Suspenders::TestHelpers - - tests Suspenders::Generators::StylesGenerator - destination Rails.root - setup :prepare_destination - teardown :restore_destination - - test "runs install script" do - output = run_generator %w[--css=tailwind] - - assert_match(/bin\/rails css:install:tailwind/, output) - end - - test "does not install modern-normalize" do - output = run_generator %w[--css=tailwind] - - assert_no_match(/add.*modern-normalize/, output) - end - - test "does not create stylesheets" do - run_generator %w[--css=tailwind] - - assert_no_file app_root("app/assets/stylesheets/base.css") - assert_no_file app_root("app/assets/stylesheets/components.css") - assert_no_file app_root("app/assets/stylesheets/utilities.css") - end - - private - - def prepare_destination - touch "Gemfile" - end - - def restore_destination - remove_file_if_exists "Gemfile" - remove_file_if_exists "package.json", root: true - remove_file_if_exists "yarn.lock", root: true - remove_file_if_exists "app/assets/stylesheets/base.css" - remove_file_if_exists "app/assets/stylesheets/components.css" - remove_file_if_exists "app/assets/stylesheets/utilities.css" - end - end - - class StylesGenerator::PostCssTest < Rails::Generators::TestCase - include Suspenders::TestHelpers - - tests Suspenders::Generators::StylesGenerator - destination Rails.root - setup :prepare_destination - teardown :restore_destination - test "installs modern-normalize and imports stylesheets" do - output = run_generator %w[--css=postcss] + output = run_generator application_stylesheet = <<~TEXT @import "modern-normalize"; @import "base.css"; @@ -197,6 +75,10 @@ class StylesGenerator::PostCssTest < Rails::Generators::TestCase end end + test "generator has a custom description" do + assert_no_match(/Description/, generator_class.desc) + end + private def prepare_destination diff --git a/test/test_helper.rb b/test/test_helper.rb index 52fc0605a..b0670b416 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -100,21 +100,6 @@ def with_test_suite(test_suite, &block) remove_dir_if_exists "spec" end - def with_css_option(css, &block) - case css - when :postcss - touch "postcss.config.js" - when :tailwind - touch "tailwind.config.js" - else - raise ArgumentError, "unknown css option: #{css.inspect}" - end - yield - ensure - remove_file_if_exists "postcss.config.js" - remove_file_if_exists "tailwind.config.js" - end - def backup_file(file) FileUtils.copy app_root(file), app_root("#{file}.bak") end