#!/usr/bin/env python3 """ Concatenate src/*.js (in filename order) into dist/jfvr.js. Each module is already a self-contained IIFE that attaches to window.__JFVR, so the build is a straight concatenation with a banner. No minification: the deployed file stays readable in DevTools, which matters because on-device debugging happens over CDP. Usage: python3 build.py # build python3 build.py --check # build + syntax check every module """ import hashlib import os import subprocess import sys HERE = os.path.dirname(os.path.abspath(__file__)) SRC = os.path.join(HERE, "src") DIST = os.path.join(HERE, "dist") OUT = os.path.join(DIST, "jfvr.js") ORDER = ["00-core.js", "10-subtitles.js", "20-controls.js", "30-hands.js", "40-watchdog.js", "90-main.js"] def sources(): """Return (path, text) for every module, in load order.""" found = sorted(f for f in os.listdir(SRC) if f.endswith(".js")) ordered = [f for f in ORDER if f in found] ordered += [f for f in found if f not in ORDER] if not ordered: sys.exit("no sources in %s" % SRC) return [(f, open(os.path.join(SRC, f), encoding="utf-8").read()) for f in ordered] def syntax_check(): bad = 0 for name, _ in sources(): p = os.path.join(SRC, name) r = subprocess.run(["node", "--check", p], capture_output=True, text=True) status = "ok" if r.returncode == 0 else "FAIL" print(" %-18s %s" % (name, status)) if r.returncode != 0: print(r.stderr.strip()) bad += 1 return bad def main(): if "--check" in sys.argv: print("syntax check:") sys.exit(1 if syntax_check() else 0) mods = sources() parts = [ "/*!", " * JFVR (Jellyfin Web VR) — built bundle. DO NOT EDIT.", " * Edit src/*.js and run: python3 build.py", " * Modules: " + ", ".join(n for n, _ in mods), " */", ] for name, text in mods: parts.append("\n/* ===== %s ===== */\n" % name) parts.append(text.rstrip("\n")) parts.append("\n") bundle = "\n".join(parts) os.makedirs(DIST, exist_ok=True) with open(OUT, "w", encoding="utf-8") as fh: fh.write(bundle) digest = hashlib.md5(bundle.encode()).hexdigest() print("built %s" % OUT) print(" modules : %d (%s)" % (len(mods), ", ".join(n for n, _ in mods))) print(" bytes : %d" % len(bundle)) print(" md5 : %s" % digest) print(" version : %s" % digest[:6]) if __name__ == "__main__": main()