~mika/www.m1kadev.nl

ref: 54d875e671b33e7f5a281378dcba7d71c40ff005 www.m1kadev.nl/build.exs -rw-r--r-- 1.0 KiB
54d875e6 — m1kadev colour redesign :)) 7 months 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
39
40
41
42
43
44
45
46
47
48
49
50
defmodule Builders do
  def html(input_path) do
    output_path = String.replace_prefix(input_path, "src", "build")

    System.cmd("html-minifier-next", [
      "--preset",
      "comprehensive",
      "-o",
      output_path,
      input_path
    ])
  end

  def css(input_path) do
    output_path = String.replace_prefix(input_path, "src", "build")

    System.cmd("lightningcss", [
      "-m",
      "-o",
      output_path,
      input_path
    ])
  end

  # TODO: js support :)
end

File.rm_rf("build")

case File.mkdir("build") do
  :ok -> {}
  _ -> raise "Couldn't create build folder"
end

case File.mkdir("build/static") do
  :ok -> {}
  _ -> raise "Couldn't create build/static folder"
end

Path.wildcard("src/**/*.html")
|> Task.async_stream(fn file -> Builders.html(file) end)
|> Enum.to_list()

Path.wildcard("src/**/*.css")
|> Task.async_stream(fn file -> Builders.css(file) end)
|> Enum.to_list()

Path.wildcard("static/**/*")
|> Task.async_stream(fn file -> File.cp(file, "build/" <> file) end)
|> Enum.to_list()