Files
anidev-design-system/scripts/package-release.py
T

27 lines
1.2 KiB
Python

"""Archive already-built, self-contained deliverables; no publishing or installation."""
import json
from pathlib import Path
from zipfile import ZipFile, ZIP_DEFLATED
root = Path(__file__).resolve().parent.parent
version = json.loads((root / "package.json").read_text(encoding="utf-8"))["version"]
dist = root / "dist"
for source, name, prefix in [
(dist / "skills/anidev-design-system", f"anidev-skill-{version}.zip", "anidev-design-system"),
(dist / "starter", f"anidev-panel-{version}.zip", "anidev-panel"),
]:
if not (source / ("SKILL.md" if "skill" in name else "index.html")).is_file():
raise SystemExit("Run npm run build:package first")
files = sorted(source.rglob("*"))
target = dist / name
with ZipFile(target, "w", ZIP_DEFLATED) as archive:
for file in files:
if file.is_symlink():
raise SystemExit(f"Symlink in release input: {file}")
if file.is_file():
archive.write(file, (Path(prefix) / file.relative_to(source)).as_posix())
with ZipFile(target) as archive:
if archive.testzip() is not None:
raise SystemExit(f"Invalid archive: {target}")
print(f"{target.name}: {len(archive.namelist())} files, CRC valid")