-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.py
More file actions
52 lines (40 loc) · 1.71 KB
/
Copy pathbuild.py
File metadata and controls
52 lines (40 loc) · 1.71 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
#!/usr/bin/env python3
"""Package dist/star-breaker.zip for itch.io.
The file list is DERIVED FROM index.html rather than hand-maintained. The
hand-maintained one silently drifted: the build that shipped was missing
src/rng.js, src/data/meta.js and the Armour/Craft/Spec/Core scenes, and RNG is
referenced on nearly every code path. Reading the <script> tags means the zip
cannot disagree with the page again.
Entries are written with forward slashes and index.html sits at the archive
root, which is what itch.io needs for a "played in browser" upload.
"""
import io
import os
import re
import sys
import zipfile
ROOT = os.path.dirname(os.path.abspath(__file__))
OUT = os.path.join(ROOT, "dist", "star-breaker.zip")
def collect():
html = io.open(os.path.join(ROOT, "index.html"), encoding="utf-8").read()
scripts = [s.split("?")[0] for s in re.findall(r'<script src="([^"]+)"', html)]
files = ["index.html"] + scripts
assets = os.path.join(ROOT, "assets")
if os.path.isdir(assets):
for base, _, names in os.walk(assets):
for name in names:
rel = os.path.relpath(os.path.join(base, name), ROOT)
files.append(rel.replace(os.sep, "/"))
return files
def main():
files = collect()
missing = [f for f in files if not os.path.exists(os.path.join(ROOT, f))]
if missing:
sys.exit("index.html references files that do not exist: %s" % missing)
os.makedirs(os.path.dirname(OUT), exist_ok=True)
with zipfile.ZipFile(OUT, "w", zipfile.ZIP_DEFLATED) as z:
for f in files:
z.write(os.path.join(ROOT, f), f)
print("%s: %d entries, %.1f KB" % (OUT, len(files), os.path.getsize(OUT) / 1024))
if __name__ == "__main__":
main()