Skip to content

Commit 131993b

Browse files
committed
Add Tailwind version compatibility check in backpex installer
1 parent 86febf4 commit 131993b

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

lib/mix/tasks/backpex.install.ex

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ if Code.ensure_loaded?(Igniter) do
8282
@impl Igniter.Mix.Task
8383
def igniter(igniter) do
8484
igniter
85+
|> check_tailwind_version()
8586
|> configure_pubsub_server()
8687
|> install_backpex_hooks()
8788
|> install_daisyui()
@@ -100,6 +101,35 @@ if Code.ensure_loaded?(Igniter) do
100101
Config.configure_new(igniter, "config.exs", :backpex, [:pubsub_server], pubsub_module)
101102
end
102103

104+
# Tailwind version check
105+
106+
defp check_tailwind_version(igniter) do
107+
with version when is_binary(version) <- Application.get_env(:tailwind, :version),
108+
true <- version_compatible?(version) do
109+
igniter
110+
else
111+
nil -> show_tailwind_warning(igniter, "no version found")
112+
false -> show_tailwind_warning(igniter, version)
113+
end
114+
end
115+
116+
defp version_compatible?(version) do
117+
[major | _rest] = String.split(version, ".")
118+
{major_num, _remainder} = Integer.parse(major)
119+
major_num >= 4
120+
end
121+
122+
defp show_tailwind_warning(igniter, version_info) do
123+
message =
124+
"No compatible Tailwind version found in config.exs (#{version_info}). Backpex requires Tailwind CSS >= 4.x.x. Do you want to continue anyway? Installation may not work correctly."
125+
126+
if IgniterIO.yes?(message) do
127+
igniter
128+
else
129+
Mix.raise("Installation cancelled. Please install Tailwind CSS >= 4.x.x and try again.")
130+
end
131+
end
132+
103133
# Backpex hooks
104134

105135
defp install_backpex_hooks(igniter) do

0 commit comments

Comments
 (0)