Skip to content

Commit 8f438f2

Browse files
committed
Log paths
1 parent e099a5d commit 8f438f2

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

apps/components_guide_web/lib/mix/tasks/template_assets.ex

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ defmodule Mix.Tasks.TemplateAssets do
77
def run(_) do
88
Mix.Task.run("app.start")
99

10+
IO.puts("Running mix template_assets in #{project_dir()}")
11+
IO.puts("Template path: #{templates_path()}")
12+
1013
image_paths = Path.wildcard(Path.join(templates_path(), "/**/*.{png,jpg,jpeg,gif}"))
14+
1115
for image_path <- image_paths do
1216
process_image(image_path)
1317
end
@@ -20,23 +24,27 @@ defmodule Mix.Tasks.TemplateAssets do
2024
Mix.shell().info("Processed #{count} file(s).")
2125
end
2226

23-
defp project_dir(), do: File.cwd!
24-
defp templates_path(), do: Path.join(project_dir(), "/apps/components_guide_web/lib/components_guide_web/templates")
25-
defp static_collected_dir(), do: Path.join(project_dir(), "/apps/components_guide_web/priv/static/collected")
27+
defp project_dir(), do: File.cwd!()
28+
29+
defp templates_path(),
30+
do: Path.join(project_dir(), "/apps/components_guide_web/lib/components_guide_web/templates")
31+
32+
defp static_collected_dir(),
33+
do: Path.join(project_dir(), "/apps/components_guide_web/priv/static/collected")
2634

2735
defp process_image(image_path) do
2836
data = File.read!(image_path)
2937
media_type = MIME.from_path(image_path)
3038
hash = :crypto.hash(:sha256, data)
3139
hash_base64 = hash |> Base.url_encode64()
32-
40+
3341
destination_dir = Path.join(static_collected_dir(), media_type)
3442
File.mkdir_p!(destination_dir)
35-
43+
3644
extension = MIME.extensions(media_type) |> List.first()
3745
destination_path = Path.join(destination_dir, "#{hash_base64}.#{extension}")
3846
File.copy!(image_path, destination_path)
39-
47+
4048
Mix.shell().info("Copied #{image_path} to #{destination_path}")
4149
end
4250
end

0 commit comments

Comments
 (0)