#!/usr/bin/env bash # schema_harvest.sh — extract Perspective component prop schemas from the running # gateway's Perspective module into per-component JSON Schema files. # # Sources (verified on 8.3.7): perspective-common-.jar inside # Perspective-module.modl carries ia.components.json (70 core components), # perspective-amcharts.components.json (ia.chart.xy/pie/gauge/simple-gauge), # perspective-timeseries.components.json, plus schemas/*.json (binding, # transform, style, view-props, session-props schemas). # # Output layout: # /components/.schema.json (the component's props JSON Schema) # /schemas/.json (binding/transform/etc. schemas) # # Usage: tools/schema_harvest.sh [output_dir] (default: .schemas/) set -euo pipefail OUT="${1:-.schemas}" TMP="$(mktemp -d)" trap 'rm -rf "$TMP"' EXIT docker cp buildathon-ignition:"/usr/local/bin/ignition/user-lib/modules/Perspective-module.modl" "$TMP/perspective.modl" python3 - "$TMP" "$OUT" <<'EOF' import json, os, sys, zipfile tmp, out = sys.argv[1], sys.argv[2] comp_dir = os.path.join(out, "components") misc_dir = os.path.join(out, "schemas") os.makedirs(comp_dir, exist_ok=True) os.makedirs(misc_dir, exist_ok=True) modl = zipfile.ZipFile(os.path.join(tmp, "perspective.modl")) total = 0 for jar in [n for n in modl.namelist() if n.endswith(".jar")]: jp = os.path.join(tmp, os.path.basename(jar)) open(jp, "wb").write(modl.read(jar)) try: z = zipfile.ZipFile(jp) except zipfile.BadZipFile: continue for entry in z.namelist(): if entry.endswith(".components.json") or entry == "ia.components.json": data = json.loads(z.read(entry)) for comp in data.get("components", []): cid = comp.get("id") if not cid: continue with open(os.path.join(comp_dir, cid + ".schema.json"), "w") as f: json.dump(comp.get("schema", {}), f, indent=1) total += 1 elif entry.startswith("schemas/") and entry.endswith(".json"): with open(os.path.join(misc_dir, os.path.basename(entry)), "wb") as f: f.write(z.read(entry)) print("extracted %d component schemas -> %s" % (total, comp_dir)) EOF ls "$OUT/components" | wc -l