Extract Tailwind release helpers

This commit is contained in:
Claudio Ortolina
2025-03-09 09:22:48 +00:00
parent be7231f5aa
commit b23e2fd1a5
3 changed files with 36 additions and 32 deletions
+4 -11
View File
@@ -8,19 +8,12 @@ defmodule Mix.Tasks.Tailwind.CheckVersion do
Exits with 0 if versions match, 1 if the Tailwind needs to be updated.
"""
alias Mix.Tasks.Tailwind.Release
@impl Mix.Task
def run(_args) do
Application.ensure_all_started(:req)
current_version =
Application.get_env(:tailwind, :version)
latest_version_url =
"https://api.github.com/repos/tailwindlabs/tailwindcss/releases/latest"
latest_version =
Req.get!(latest_version_url).body["tag_name"]
|> String.replace_prefix("v", "")
current_version = Release.fetch_current_version()
latest_version = Release.fetch_latest_version!()
if current_version !== latest_version do
Mix.Shell.IO.info(
+27
View File
@@ -0,0 +1,27 @@
defmodule Mix.Tasks.Tailwind.Release do
@latest_version_url "https://api.github.com/repos/tailwindlabs/tailwindcss/releases/latest"
def fetch_latest_version! do
Application.ensure_all_started(:req)
Req.get!(@latest_version_url).body["tag_name"]
|> String.replace_prefix("v", "")
end
def fetch_current_version do
Application.get_env(:tailwind, :version)
end
def update_config_file!(config_file, current_version, latest_version) do
config_contents = File.read!(config_file)
new_config_contents =
String.replace(
config_contents,
~s(version: "#{current_version}"),
"version: \"#{latest_version}\""
)
File.write!(config_file, new_config_contents)
end
end
+5 -21
View File
@@ -6,19 +6,12 @@ defmodule Mix.Tasks.Tailwind.UpdateVersion do
Update the configured tailwind versino to latest.
"""
alias Mix.Tasks.Tailwind.Release
@impl Mix.Task
def run(_args) do
Application.ensure_all_started(:req)
current_version =
Application.get_env(:tailwind, :version)
latest_version_url =
"https://api.github.com/repos/tailwindlabs/tailwindcss/releases/latest"
latest_version =
Req.get!(latest_version_url).body["tag_name"]
|> String.replace_prefix("v", "")
current_version = Release.fetch_current_version()
latest_version = Release.fetch_latest_version!()
if current_version !== latest_version do
Mix.Shell.IO.info(
@@ -28,16 +21,7 @@ defmodule Mix.Tasks.Tailwind.UpdateVersion do
config_file =
Path.expand("config/config.exs", File.cwd!())
config_contents = File.read!(config_file)
new_config_contents =
String.replace(
config_contents,
~s(version: "#{current_version}"),
"version: \"#{latest_version}\""
)
File.write!(config_file, new_config_contents)
Release.update_config_file!(config_file, current_version, latest_version)
else
Mix.Shell.IO.info("tailwind configuration is up to date (#{current_version})")
end