forked from b.peck/BAT
Gate G0 green: scan clean, lint 0 failures, clients 200, probe P0 facts captured, simulator journaling. Probe locked: uuid row grouping, compound AlarmState strings, java-exception bare-except gotcha, millis dates OK, ackUserName field. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
56 lines
2.3 KiB
Bash
Executable File
56 lines
2.3 KiB
Bash
Executable File
#!/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-<ver>.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:
|
|
# <out>/components/<component-id>.schema.json (the component's props JSON Schema)
|
|
# <out>/schemas/<name>.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
|