-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.py
More file actions
executable file
·53 lines (47 loc) · 2.59 KB
/
build.py
File metadata and controls
executable file
·53 lines (47 loc) · 2.59 KB
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
from collections.abc import Mapping
import subprocess
from pathlib import Path
import json
from typing import Any
colors = list(Path("./colors").glob("*"))
svgs = list(Path("./source").glob("**/*.svg"))
sizes = [ 500, 10000 ]
script = ""
for svg in svgs:
for size in sizes:
name = svg.name.split(".")[0]
parent = svg.parent
template = (parent / f"{name}.json")
for color in colors:
cname = color.name.split(".")[0]
fname = svg.parent / f"{cname}-{size}-{svg.name}"
script += f'''
source {color.absolute()}
cat {svg.absolute()} |
xmlstarlet ed -N s=http://www.w3.org/2000/svg -u "/s:svg/s:defs/s:linearGradient[@inkscape:label='FG']/s:stop/@style" -v "stop-color:$FG;stop-opacity:1;" |\
xmlstarlet ed -N s=http://www.w3.org/2000/svg -u "/s:svg/s:defs/s:linearGradient[@inkscape:label='BG']/s:stop/@style" -v "stop-color:$BG;stop-opacity:1;" >\
./{fname}
'''
if template.exists():
temp_vals: list[Mapping[str, Any]] = json.loads(template.read_text()) # pyright: ignore[reportExplicitAny, reportAny]
for item in temp_vals:
temp_fname = fname.parent / f"{item.get("id", "")}-{fname.name}"
for val in item:
script += f'''
export {val}="{item[val]}"
'''
script += f'''
mkdir -p out/{svg.parent}
envsubst -i ./{fname} -o "out/{temp_fname}"
inkscape -o "./out/{temp_fname}" --export-type=svg --export-plain-svg "./out/{temp_fname}"
inkscape -o "./out/{temp_fname.parent}/solid-{temp_fname.name}" --export-type=png --export-width={size} --export-background=$BG "./out/{temp_fname}"
inkscape -o "./out/{temp_fname.parent}/clear-{temp_fname.name}" --export-type=png --export-width={size} "./out/{temp_fname}"
'''
else:
script += f'''
inkscape -o "./out/{fname}" --export-type=svg --export-plain-svg "./{fname}"
inkscape -o "./out/{fname.parent}/solid-{fname.name}" --export-type=png --export-width={size} --export-background=$BG "./out/{fname}"
inkscape -o "./out/{fname.parent}/clear-{fname.name}" --export-type=png --export-width={size} "./out/{fname}"
'''
print(script)
_ = subprocess.run(["bash", "-c", script], check=True, stderr=subprocess.STDOUT)