-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.py
executable file
·67 lines (48 loc) · 1.91 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env python
# based on: https://fontforge.org/docs/scripting/python.html#fontforge-as-a-python-extension
# doc: https://fontforge.org/docs/scripting/python/fontforge.html
# === Prerequisite ===
# 1. FontForge and its Python bidings installed on the system:
# sudo apt install fontforge python3-fontforge
# 2. A git worktree initialized in the public folder:
# git checkout --orphan public
# git reset --hard
# git checkout main
# git worktree add public public
from pathlib import Path
from shutil import copy
import sys
import subprocess
import fontforge
PROJECT_DIR = Path(__file__).parent
WEBSITE_DIR = PROJECT_DIR / 'website'
SOURCE_DIR = PROJECT_DIR / 'sources'
DIST_DIR = PROJECT_DIR / 'dist'
PUBLIC_DIR = PROJECT_DIR / 'public'
FONT_SVG_PATH = SOURCE_DIR / 'font.svg'
FONT_TTF_PATH = DIST_DIR / 'hexagon_drawing.ttf'
WEBSITE_CSS_PATH = WEBSITE_DIR / 'index.html'
WEBSITE_HTML_PATH = WEBSITE_DIR / 'style.css'
def build_ttf():
FONT_TTF_PATH.parent.mkdir(parents=True, exist_ok=True)
font = fontforge.open(str(FONT_SVG_PATH))
font.correctDirection()
font.generate(str(FONT_TTF_PATH))
font.close()
def build_public():
PUBLIC_DIR.mkdir(parents=True, exist_ok=True)
for f in PUBLIC_DIR.iterdir():
f.unlink()
copy(WEBSITE_HTML_PATH, PUBLIC_DIR)
copy(WEBSITE_CSS_PATH, PUBLIC_DIR)
copy(FONT_TTF_PATH, PUBLIC_DIR)
def deploy():
subprocess.check_call(['git', 'pull'], cwd=PUBLIC_DIR)
subprocess.check_call(['git', 'commit', '--amend', '--message', 'update website'], cwd=PUBLIC_DIR)
subprocess.check_call(['git', 'push', '--force', 'origin', 'public'], cwd=PUBLIC_DIR)
if __name__ == '__main__':
commands = { 'ttf': build_ttf, 'public': build_public, 'deploy': deploy }
if len(sys.argv) != 2 or sys.argv[1] not in commands:
print(f"Usage: { sys.argv[0] } [{ ' | '.join(commands) }]")
sys.exit(1)
commands[sys.argv[1]]()