From 7ae099524bca2ea16c8972a2e573376511f806e2 Mon Sep 17 00:00:00 2001 From: Claudio Ortolina Date: Thu, 6 Mar 2025 15:33:17 +0000 Subject: [PATCH] Add Mix task to update Tailwind version --- lib/mix/tasks/tailwind/update_version.ex | 45 ++++++++++++++++++++++++ mise.toml | 7 +++- 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 lib/mix/tasks/tailwind/update_version.ex diff --git a/lib/mix/tasks/tailwind/update_version.ex b/lib/mix/tasks/tailwind/update_version.ex new file mode 100644 index 00000000..fefe41ed --- /dev/null +++ b/lib/mix/tasks/tailwind/update_version.ex @@ -0,0 +1,45 @@ +defmodule Mix.Tasks.Tailwind.UpdateVersion do + use Mix.Task + + @shortdoc "Update the configured tailwind versino to latest." + @moduledoc """ + Update the configured tailwind versino to latest. + """ + + @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", "") + + if current_version !== latest_version do + Mix.Shell.IO.info( + "Updating tailwind configuration from #{current_version} to #{latest_version}" + ) + + config_file = + Path.expand("config/config.exs", File.cwd!()) + + config_contents = File.read!(config_file) + + new_config_contents = + String.replace( + config_contents, + ~r{version: "#{current_version}"}, + "version: \"#{latest_version}\"" + ) + + File.write!(config_file, new_config_contents) + else + Mix.Shell.IO.info("tailwind configuration is up to date (#{current_version})") + end + end +end diff --git a/mise.toml b/mise.toml index 78876073..08174e98 100644 --- a/mise.toml +++ b/mise.toml @@ -24,13 +24,18 @@ run = 'npm outdated' hide = true dir = 'assets' +[tasks.tailwind-update] +description = 'Update the Tailwind version configured in the project' +run = 'mix tailwind.update_version' +hide = true + [tasks.setup] depends = ['npm-install'] description = 'Install dependencies and setup the database' run = ['mix setup'] [tasks.deps-update] -depends = ['npm-update'] +depends = ['npm-update', 'tailwind-update'] description = 'Update dependencies' run = ['mix deps.update --all']