-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.py
48 lines (35 loc) · 1.15 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
46
47
48
from pathlib import Path
import shutil
import subprocess
DIR_ = Path(__file__).parent
VERSION_STRING_PATH = DIR_ / "version_string.txt"
SRC_DIR = DIR_ / "src"
SERVER_TEMPLATE_DIR = SRC_DIR / "server_template"
DIST_DIR = DIR_ / "dist"
VERSION_STRING = str(int(VERSION_STRING_PATH.read_text()) + 1)
VERSION_STRING_PATH.write_text(VERSION_STRING)
def remove_old_dist_dir():
if DIST_DIR.exists():
shutil.rmtree(DIST_DIR)
def copy_and_fill_in_template(src, dst):
if src.is_dir():
dst.mkdir()
for src_child in src.iterdir():
dst_child = dst / src_child.name
copy_and_fill_in_template(src_child, dst_child)
else:
shutil.copy(src, dst)
if dst.suffix in [".html", ".php", ".js"]:
old_text = dst.read_text()
new_text = old_text.replace("!VERSION_STRING", VERSION_STRING)
dst.write_text(new_text)
def process_scss():
subprocess.run([
"sass",
"--load-path=src/scss",
"--style=compressed",
"src/scss:dist/public_html/generated-css"
])
remove_old_dist_dir()
copy_and_fill_in_template(SERVER_TEMPLATE_DIR, DIST_DIR)
process_scss()