-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.py
45 lines (42 loc) · 1.33 KB
/
build.py
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
import pathlib
import re
import os
import shutil
import subprocess
dist = pathlib.Path("dist")
src = pathlib.Path("src")
dist.mkdir(exist_ok=True)
for file in dist.glob("*"):
os.remove(file)
for filepath in src.glob("*"):
if filepath.name == "nord.css": continue
with open(filepath, encoding="utf8") as file:
file_content = file.read()
match filepath.suffix:
case ".html":
with open(dist / filepath.name, "w", encoding="utf8") as f:
f.write(re.sub("\n *", "", file_content))
case ".scss":
pass
case ".js":
with open(dist / filepath.name, "w", encoding="utf8") as f:
f.write(
subprocess.run(
["uglifyjs", filepath],
shell=True,
capture_output=True,
encoding="utf-8",
text=True
).stdout
)
case ".css":
subprocess.run(
["cleancss", "-O2", filepath, '>', f"dist/{filepath.name}"],
shell=True,
capture_output=True,
encoding="utf-8",
text=True
).stdout
case _:
shutil.copy2(filepath, f"dist/{filepath.name}")
print(f"✅ {filepath}")