~mika/www.m1kadev.nl

ref: 864f33dd4b323f6832ebe0e31c519e98a0287257 www.m1kadev.nl/kethel/lib/bricks.ex -rw-r--r-- 1.5 KiB
864f33dd — m1ka fix greets on mobile (i think) a month ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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 <a href="https://codeberg.org/m1ka/www.m1kadev.nl/commit/#{git_commit}">#{git_commit |> binary_slice(0..7)}</a>, on #{build_date |> String.trim()}.
    """

    extended_footer = """
      Built from commit <a href="https://codeberg.org/m1ka/www.m1kadev.nl/commit/#{git_commit}">#{git_commit |> String.trim()}</a>, using #{lcss_version |> String.trim()},
      html-minifier-next version #{hmn_version |> String.trim()}, #{ujs_version |> String.trim()}, on #{e_build_date |> String.trim()}.
    """

    Map.merge(%{build_info: footer, extended_build_info: extended_footer}, from_files)
  end
end