Fix update

This commit is contained in:
Nuno Freire
2022-09-01 15:45:27 +01:00
parent 788c3c92b0
commit 74ec263231

View File

@ -38,11 +38,10 @@ defmodule Heroicons do
@doc false @doc false
def svgs_path, do: Path.join(:code.priv_dir(:heroicons), "icons") def svgs_path, do: Path.join(:code.priv_dir(:heroicons), "icons")
def icons_path(style), do: Path.join(svgs_path(), style)
def update do def update do
version = configured_version() version = configured_version()
tmp_dir = Path.join(System.tmp_dir!(), @tmp_dir_name) tmp_dir = Path.join(System.tmp_dir!(), @tmp_dir_name)
svgs_dir = Path.join([tmp_dir, "heroicons-#{version}", "optimized"])
File.rm_rf!(tmp_dir) File.rm_rf!(tmp_dir)
File.mkdir_p!(tmp_dir) File.mkdir_p!(tmp_dir)
@ -56,22 +55,27 @@ defmodule Heroicons do
end end
# Copy icon styles, mini, outline and solid, to priv folder # Copy icon styles, mini, outline and solid, to priv folder
Path.join([tmp_dir, "heroicons-#{version}", "optimized"]) svgs_dir
|> File.ls!() |> File.ls!()
|> Enum.each(fn size -> |> Enum.each(fn size ->
case size do case size do
"20" -> copy_svg_files(size, "solid", "mini") "20" ->
"24" -> Enum.each(File.ls!(), fn style -> copy_svg_files(size, style, style) end) copy_svg_files(Path.join([svgs_dir, size, "solid"]), "mini")
_ -> true
"24" ->
Path.join(svgs_dir, size)
|> File.ls!()
|> Enum.each(fn style -> copy_svg_files(Path.join([svgs_dir, size, style]), style) end)
_ ->
true
end end
end) end)
end end
defp copy_svg_files(icons_size, src_dir_name, output_dir_name) do defp copy_svg_files(src_dir, style) do
tmp_dir = Path.join(System.tmp_dir!(), @tmp_dir_name) dest_dir = Path.join(svgs_path(), style)
svgs_temp_dir = Path.join([tmp_dir, "heroicons-#{configured_version()}", "optimized"]) File.cp_r!(src_dir, dest_dir)
File.cp_r!(Path.join([svgs_temp_dir, icons_size, src_dir_name]), icons_path(output_dir_name))
end end
defp fetch_body!(url) do defp fetch_body!(url) do