Add Mix task to update Tailwind version
This commit is contained in:
@@ -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
|
||||
@@ -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']
|
||||
|
||||
|
||||
Reference in New Issue
Block a user