Extract Tailwind release helpers
This commit is contained in:
@@ -8,19 +8,12 @@ defmodule Mix.Tasks.Tailwind.CheckVersion do
|
|||||||
Exits with 0 if versions match, 1 if the Tailwind needs to be updated.
|
Exits with 0 if versions match, 1 if the Tailwind needs to be updated.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
alias Mix.Tasks.Tailwind.Release
|
||||||
|
|
||||||
@impl Mix.Task
|
@impl Mix.Task
|
||||||
def run(_args) do
|
def run(_args) do
|
||||||
Application.ensure_all_started(:req)
|
current_version = Release.fetch_current_version()
|
||||||
|
latest_version = Release.fetch_latest_version!()
|
||||||
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
|
if current_version !== latest_version do
|
||||||
Mix.Shell.IO.info(
|
Mix.Shell.IO.info(
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -6,19 +6,12 @@ defmodule Mix.Tasks.Tailwind.UpdateVersion do
|
|||||||
Update the configured tailwind versino to latest.
|
Update the configured tailwind versino to latest.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
alias Mix.Tasks.Tailwind.Release
|
||||||
|
|
||||||
@impl Mix.Task
|
@impl Mix.Task
|
||||||
def run(_args) do
|
def run(_args) do
|
||||||
Application.ensure_all_started(:req)
|
current_version = Release.fetch_current_version()
|
||||||
|
latest_version = Release.fetch_latest_version!()
|
||||||
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
|
if current_version !== latest_version do
|
||||||
Mix.Shell.IO.info(
|
Mix.Shell.IO.info(
|
||||||
@@ -28,16 +21,7 @@ defmodule Mix.Tasks.Tailwind.UpdateVersion do
|
|||||||
config_file =
|
config_file =
|
||||||
Path.expand("config/config.exs", File.cwd!())
|
Path.expand("config/config.exs", File.cwd!())
|
||||||
|
|
||||||
config_contents = File.read!(config_file)
|
Release.update_config_file!(config_file, current_version, latest_version)
|
||||||
|
|
||||||
new_config_contents =
|
|
||||||
String.replace(
|
|
||||||
config_contents,
|
|
||||||
~s(version: "#{current_version}"),
|
|
||||||
"version: \"#{latest_version}\""
|
|
||||||
)
|
|
||||||
|
|
||||||
File.write!(config_file, new_config_contents)
|
|
||||||
else
|
else
|
||||||
Mix.Shell.IO.info("tailwind configuration is up to date (#{current_version})")
|
Mix.Shell.IO.info("tailwind configuration is up to date (#{current_version})")
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user