28 lines
1.4 KiB
Python
28 lines
1.4 KiB
Python
"""Build the original assembly example offline from licensed local assets."""
|
|
from pathlib import Path
|
|
import base64
|
|
import hashlib
|
|
import json
|
|
import re
|
|
|
|
root = Path(__file__).resolve().parents[1]
|
|
for entry in json.loads((root / 'vendor-manifest.json').read_text()):
|
|
assert hashlib.sha256((root / entry['path']).read_bytes()).hexdigest() == entry['sha256']
|
|
vendor = root / 'assets/vendor'
|
|
text = (root / 'assets/mechanism.html').read_text()
|
|
js = re.sub(r'//# sourceMappingURL=.*', '', (vendor / 'anime.umd.min.js').read_text())
|
|
text = text.replace('/* ANIME_JS */', js)
|
|
fonts = ''
|
|
for file, weight in [('work-sans.woff2', 400), ('work-sans-bold.woff2', 700)]:
|
|
data = base64.b64encode((vendor / file).read_bytes()).decode()
|
|
fonts += f"@font-face{{font-family:'Work Sans';font-weight:{weight};src:url(data:font/woff2;base64,{data}) format('woff2');}}"
|
|
text = text.replace('/* FONT_CSS */', fonts)
|
|
notices = '\n'.join((vendor / f).read_text() for f in ['anime-LICENSE.md', 'work-sans-LICENSE'])
|
|
text = text.replace('<!-- LICENSES -->', '<!-- THIRD-PARTY NOTICES\n' + notices.replace('--', '—') + '\n-->')
|
|
out = root / 'dist/mechanism-demo-0.2.0.html'
|
|
out.parent.mkdir(exist_ok=True)
|
|
out.write_text(text)
|
|
report = {'file': out.name, 'sha256': hashlib.sha256(out.read_bytes()).hexdigest(), 'interactive_components': 3, 'controls': 4, 'anime': '4.5.0'}
|
|
(root / 'dist/mechanism-manifest.json').write_text(json.dumps(report, indent=2) + '\n')
|
|
print(json.dumps(report))
|