| 1 | #!/usr/bin/env bash |
| 2 | # Validate datapack metadata: pack.mcmeta is JSON with pack.pack_format, |
| 3 | # and every .json file under data/ parses as JSON. |
| 4 | set -euo pipefail |
| 5 | root="$(cd "$(dirname "$0")/../.." && pwd)" |
| 6 | cd "$root" |
| 7 | python3 - <<'PY' |
| 8 | import json, sys |
| 9 | from pathlib import Path |
| 10 | |
| 11 | root = Path(".") |
| 12 | errors = [] |
| 13 | |
| 14 | meta_path = root / "pack.mcmeta" |
| 15 | if not meta_path.is_file(): |
| 16 | errors.append("pack.mcmeta ontbreekt") |
| 17 | else: |
| 18 | try: |
| 19 | meta = json.loads(meta_path.read_text(encoding="utf-8")) |
| 20 | except json.JSONDecodeError as e: |
| 21 | errors.append(f"pack.mcmeta is geen geldige JSON: {e}") |
| 22 | meta = None |
| 23 | if meta is not None: |
| 24 | pack = meta.get("pack") if isinstance(meta, dict) else None |
| 25 | if not isinstance(pack, dict) or "pack_format" not in pack: |
| 26 | errors.append("pack.mcmeta mist pack.pack_format") |
| 27 | elif pack["pack_format"] in (None, "", []): |
| 28 | errors.append("pack.mcmeta heeft een lege pack.pack_format") |
| 29 | |
| 30 | data = root / "data" |
| 31 | if not data.is_dir(): |
| 32 | errors.append("data/ ontbreekt") |
| 33 | else: |
| 34 | files = sorted(data.rglob("*.json")) |
| 35 | if not files: |
| 36 | errors.append("geen .json-bestanden onder data/") |
| 37 | for path in files: |
| 38 | try: |
| 39 | json.loads(path.read_text(encoding="utf-8")) |
| 40 | except json.JSONDecodeError as e: |
| 41 | errors.append(f"{path}: geen geldige JSON: {e}") |
| 42 | |
| 43 | if errors: |
| 44 | print("Validatie mislukt:", file=sys.stderr) |
| 45 | for e in errors: |
| 46 | print(f" - {e}", file=sys.stderr) |
| 47 | sys.exit(1) |
| 48 | |
| 49 | print("Validatie geslaagd: pack.mcmeta en alle JSON onder data/ zijn in orde.") |
| 50 | PY |