Skip to content

Commit fef615c

Browse files
committed
If present, move config/postcss.config.js to root
This is where the tailwind upgrade tool expects it to be, because that's the convention, apparently.
1 parent 25010f3 commit fef615c

File tree

2 files changed

+39
-18
lines changed

2 files changed

+39
-18
lines changed

Diff for: lib/install/upgrade_tailwindcss.rb

+24-18
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,34 @@
11
TAILWIND_CONFIG_PATH = Rails.root.join("config/tailwind.config.js")
22
APPLICATION_LAYOUT_PATH = Rails.root.join("app/views/layouts/application.html.erb")
3+
POSTCSS_CONFIG_PATH = Rails.root.join("config/postcss.config.js")
34

4-
if TAILWIND_CONFIG_PATH.exist?
5-
if File.read(TAILWIND_CONFIG_PATH).match?(/defaultTheme/)
6-
say "Removing references to 'defaultTheme' from #{TAILWIND_CONFIG_PATH}"
7-
gsub_file TAILWIND_CONFIG_PATH.to_s, /^(.*defaultTheme)/, "// \\1"
8-
end
5+
unless TAILWIND_CONFIG_PATH.exist?
6+
say "Default tailwind.config.js is missing!", :red
7+
abort
8+
end
99

10-
if system("npx --version")
11-
say "Running the upstream Tailwind CSS upgrader"
12-
command = Shellwords.join(["npx", "@tailwindcss/upgrade@next", "--force", "--config", TAILWIND_CONFIG_PATH.to_s])
13-
success = run(command, abort_on_failure: false)
14-
unless success
15-
say "The upgrade tool failed!", :red
16-
say %( You probably need to update your configuration. Please read the error messages,)
17-
say %( and check the Tailwind CSS upgrade guide at https://tailwindcss.com/docs/upgrade-guide.)
18-
abort
19-
end
20-
else
21-
say "Could not run the Tailwind upgrade tool. Please see https://tailwindcss.com/docs/upgrade-guide for manual instructions.", :red
10+
if File.read(TAILWIND_CONFIG_PATH).match?(/defaultTheme/)
11+
say "Removing references to 'defaultTheme' from #{TAILWIND_CONFIG_PATH}"
12+
gsub_file TAILWIND_CONFIG_PATH.to_s, /^(.*defaultTheme)/, "// \\1"
13+
end
14+
15+
if POSTCSS_CONFIG_PATH.exist?
16+
say "Moving PostCSS configuration to application root directory"
17+
FileUtils.mv(POSTCSS_CONFIG_PATH, Rails.root, verbose: true) || abort
18+
end
19+
20+
if system("npx --version")
21+
say "Running the upstream Tailwind CSS upgrader"
22+
command = Shellwords.join(["npx", "@tailwindcss/upgrade@next", "--force", "--config", TAILWIND_CONFIG_PATH.to_s])
23+
success = run(command, abort_on_failure: false)
24+
unless success
25+
say "The upgrade tool failed!", :red
26+
say %( You probably need to update your configuration. Please read the error messages,)
27+
say %( and check the Tailwind CSS upgrade guide at https://tailwindcss.com/docs/upgrade-guide.)
2228
abort
2329
end
2430
else
25-
say "Default tailwind.config.js is missing!", :red
31+
say "Could not run the Tailwind upgrade tool. Please see https://tailwindcss.com/docs/upgrade-guide for manual instructions.", :red
2632
abort
2733
end
2834

Diff for: test/integration/user_upgrade_test.sh

+15
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,15 @@ bundle install --prefer-local
5757
bundle show --paths
5858
bundle binstubs --all
5959

60+
# create a postcss file
61+
cat <<EOF > config/postcss.config.js
62+
module.exports = {
63+
plugins: {
64+
autoprefixer: {},
65+
},
66+
}
67+
EOF
68+
6069
bin/rails tailwindcss:upgrade
6170

6271
# TEST: removal of inter-font CSS
@@ -65,6 +74,12 @@ if grep -q inter-font app/views/layouts/application.html.erb ; then
6574
exit 1
6675
fi
6776

77+
# TEST: moving the postcss file
78+
if [ ! -f postcss.config.js ] ; then
79+
echo "FAIL: postcss.config.js not moved"
80+
exit 1
81+
fi
82+
6883
# generate CSS
6984
bin/rails tailwindcss:build[verbose]
7085
grep -q "py-2" app/assets/builds/tailwind.css

0 commit comments

Comments
 (0)