Files
adaptive-music/scripts/package_module.py
T

50 lines
2.8 KiB
Python

"""Build a local development ZIP from an explicit public browser-source allowlist."""
import json
from pathlib import Path
import zipfile
ROOT = Path(__file__).resolve().parents[1]
def build(destination=None):
destination = destination or ROOT / 'dist/adaptive-music-dev.zip'
destination.parent.mkdir(parents=True,exist_ok=True)
names = ['module.json','LICENSE','THIRD-PARTY-NOTICES','README.md','INSTALL.md','CHANGELOG.md','ARCHITECTURE.md','SECURITY.md','TESTING.md','PROGRESS.md']
names += [str(p.relative_to(ROOT)) for p in sorted((ROOT/'src').rglob('*.mjs'))]
names += [str(p.relative_to(ROOT)) for p in sorted((ROOT/'licenses').rglob('*.txt'))]
names += [str(p.relative_to(ROOT)) for p in sorted((ROOT/'styles').glob('*.css'))]
names += [str(p.relative_to(ROOT)) for p in sorted((ROOT/'vendor').glob('*')) if p.is_file()]
manifest=json.loads((ROOT/'module.json').read_text())
if manifest['id']!='adaptive-music' or 'verified' in manifest['compatibility']:
raise ValueError('invalid development manifest')
with zipfile.ZipFile(destination,'w',zipfile.ZIP_DEFLATED) as archive:
for name in names:
path=ROOT/name
if path.is_symlink(): raise ValueError('symlink refused')
data=path.read_bytes()
if name.endswith('.mjs') and (b'node:' in data or b'gateway/' in data):
raise ValueError('server source in browser package')
entry=zipfile.ZipInfo('adaptive-music/'+name,date_time=(2026,12,3,0,0,0))
entry.compress_type=zipfile.ZIP_DEFLATED
entry.external_attr=0o100644<<16
archive.writestr(entry,data)
return destination
def build_companion(destination=None):
destination=destination or ROOT/'dist/adaptive-music-companion-dev.zip'
destination.parent.mkdir(parents=True,exist_ok=True)
names=['LICENSE','THIRD-PARTY-NOTICES','package.json','package-lock.json','src/core/controller.mjs','src/providers/ma/client.mjs','src/providers/ma/provider.mjs','src/providers/ma/webcrypto.mjs']
names += [str(p.relative_to(ROOT)) for p in sorted((ROOT/'gateway').glob('*.mjs'))]
names += ['gateway/README.md','gateway/SETUP.md']
names += [str(p.relative_to(ROOT)) for p in sorted((ROOT/'licenses').rglob('*.txt'))]
with zipfile.ZipFile(destination,'w',zipfile.ZIP_DEFLATED) as archive:
for name in names:
path=ROOT/name
if path.is_symlink(): raise ValueError('symlink refused')
entry=zipfile.ZipInfo('adaptive-music-companion/'+name,date_time=(2026,12,3,0,0,0))
entry.compress_type=zipfile.ZIP_DEFLATED;entry.external_attr=0o100644<<16
archive.writestr(entry,path.read_bytes())
return destination
if __name__=='__main__':
print(build().relative_to(ROOT))
# The optional companion remains source/experimental fallback, not a required release artifact.