From 0b0492a724b1e2d0434de9067d9197ae78fde559 Mon Sep 17 00:00:00 2001 From: Graham Forest Date: Mon, 22 Dec 2025 11:01:14 -0800 Subject: [PATCH] Add a tool to show changes vs the published schema `bin/diff-dat-schema` refreshes a local copy of the published schema (efficiently), then sorts, filters, and version-filters for each game version to show a summary of what changed. Made this while verifying my own programmatic manipulation code, but it seems generally useful. --- .gitignore | 1 + bin/diff-dat-schema | 45 +++++++++++++++++++++++++++++++++++++++++++++ package.json | 3 ++- 3 files changed, 48 insertions(+), 1 deletion(-) create mode 100755 bin/diff-dat-schema diff --git a/.gitignore b/.gitignore index 7bf05ba..6d2e3ab 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ dist/ schema.min.json schema.jsonl +upstream.min.json # Logs logs diff --git a/bin/diff-dat-schema b/bin/diff-dat-schema new file mode 100755 index 0000000..1bd3044 --- /dev/null +++ b/bin/diff-dat-schema @@ -0,0 +1,45 @@ +#!/bin/bash -e + +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +cd "$SCRIPT_DIR/.." || exit + +BOLD="$(tput bold)" +NORM="$(tput sgr0)" + +TMPD=$(mktemp -d .dat-schema-XXX) +trap 'rm -rf -- "$TMPD"' EXIT + +filter() { + jq '.tables | sort_by(.name)[] | select(.validFor == '"$1"' or .validFor == 3) | del(.validFor)' "$2" > "$3" +} + +UPSTREAM="upstream.min.json" +NEW="schema.min.json" + +# -c won't download unless upstream is newer +wget -O "$UPSTREAM" -q -c https://github.com/poe-tool-dev/dat-schema/releases/download/latest/schema.min.json + +CHANGES=no + +for V in 1 2 +do + UPSTREAMV="$TMPD/upstream.$V.json" + NEWV="$TMPD/schema.$V.json" + TMPV="$TMPD/schema.$V.diff" + filter "$V" "$UPSTREAM" "$UPSTREAMV" + filter "$V" "$NEW" "$NEWV" + if ! diff -u "$UPSTREAMV" "$NEWV" > "$TMPV" + then + CHANGES=yes + echo "${BOLD}Changes for Version $V:${NORM}" + tail -n +3 < "$TMPV" + echo + fi +done + +if [ "$CHANGES" == "yes" ] +then + echo "Note: The above diff is against the published schema which may be behind the main branch" +else + echo "No changes detected" +fi diff --git a/package.json b/package.json index 486a8d7..5fc4356 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,8 @@ "exports": "./dist/index.js", "scripts": { "generate": "tsc --noCheck && node dist/cli.js", - "generate:watch": "tsc --noCheck && node dist/cli.js --watch" + "generate:watch": "tsc --noCheck && node dist/cli.js --watch", + "diff": "./bin/diff-dat-schema" }, "files": [ "dist/index.*",