-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_zip.py
More file actions
87 lines (72 loc) · 2.54 KB
/
Copy pathbuild_zip.py
File metadata and controls
87 lines (72 loc) · 2.54 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
"""Build distribution ZIPs for Chrome Web Store / Firefox AMO / Edge Add-ons.
All three stores accept the same zip — the only thing Firefox is stricter
about is no inline <script>/<style> (handled by extracting options.js +
options.css) and explicit "permissions" in manifest (handled by adding
"storage" to permissions array).
Output:
growth-math-v<version>.zip — runtime only, suitable for all 3 stores
Excludes:
- generate_*.py, render_*.py, test_*.py, build_zip.py, _retry_hero.py
(Python tooling that never needs to ship to users)
- promo/, README.md, SUBMISSION.md, .gitignore
(developer-only assets and docs)
- icon.svg
(PNG icons listed in manifest are what stores read; SVG is source)
Run:
python extension/build_zip.py
"""
import json
import os
import sys
import zipfile
from pathlib import Path
EXT_DIR = Path(__file__).parent
ROOT = EXT_DIR.parent
def main():
manifest_path = EXT_DIR / 'manifest.json'
manifest = json.loads(manifest_path.read_text(encoding='utf-8'))
version = manifest['version']
out = ROOT / f'growth-math-v{version}.zip'
# Whitelist — exactly what users need at runtime
runtime_files = [
'manifest.json',
'popup.html',
'popup.css',
'popup.js',
'options.html',
'options.css',
'options.js',
'_locales/en/messages.json',
'_locales/ru/messages.json',
'icons/icon-16.png',
'icons/icon-32.png',
'icons/icon-48.png',
'icons/icon-128.png',
]
missing = []
with zipfile.ZipFile(out, 'w', zipfile.ZIP_DEFLATED, compresslevel=9) as zf:
for rel in runtime_files:
src = EXT_DIR / rel
if not src.exists():
missing.append(rel)
continue
zf.write(src, arcname=rel)
if missing:
sys.stderr.write(f'[ERROR] Missing files (will reject by stores):\n')
for m in missing:
sys.stderr.write(f' - {m}\n')
sys.exit(1)
size_kb = out.stat().st_size / 1024
sys.stderr.write(f'\n[OK] Built {out.name}\n')
sys.stderr.write(f' path: {out}\n')
sys.stderr.write(f' size: {size_kb:.1f} KB\n')
sys.stderr.write(f' version: {version}\n')
sys.stderr.write(f' files: {len(runtime_files)}\n')
# Print contents for verification
sys.stderr.write('\n Contents:\n')
with zipfile.ZipFile(out) as zf:
for n in zf.namelist():
info = zf.getinfo(n)
sys.stderr.write(f' {info.file_size:>7,} B {n}\n')
if __name__ == '__main__':
main()