defmodule Bricks do
@typedoc "A path, relative to mix.exs"
@type relative_path() :: binary()
@typedoc "The name of the brick"
@type brick_name() :: binary()
@typedoc "A valid mustache template"
@type mustache() :: binary()
@type bricks() :: %{brick_name() => mustache()}
@spec collect(relative_path()) :: bricks()
def collect(folder) do
from_files =
Path.wildcard(folder <> "/bricks/*.thtml")
|> Map.new(fn x -> {FileX.trimmed_filename(x), File.read!(x)} end)
{lcss_version, 0} = System.cmd("npx", ["lightningcss", "-V"])
{hmn_version, 0} = System.cmd("npx", ["html-minifier-next", "-V"])
{ujs_version, 0} = System.cmd("npx", ["uglifyjs", "-V"])
{git_commit, 0} = System.cmd("git", ["rev-parse", "HEAD"])
{build_date, 0} = System.cmd("date", ["+%H:%M %d/%m/%y"])
{e_build_date, 0} = System.cmd("date", ["+%H:%M:%S %d/%m/%y"])
footer = """
Built from commit #{git_commit |> binary_slice(0..7)}, on #{build_date}
"""
extended_footer = """
Built from commit #{git_commit |> String.trim()}, using lightningcss #{lcss_version},
html-minifier-next version #{hmn_version}, uglifyjs version #{ujs_version}, on #{e_build_date}
"""
Map.merge(%{footer: footer, extended_footer: extended_footer}, from_files)
end
end