#!/usr/bin/env bash # # Fails when frontend/wailsjs/ is stale against the bound Go structs. # # frontend/wailsjs/ is generated by `wails`, not by `go generate`, so the # pre-commit codegen check does not cover it at all. Without this, a # renamed Go struct field or a changed method signature first shows up at # runtime, inside a window, as a binding that never settles. # # `wails generate module` builds the app with the `bindings` tag and runs # it to dump the bindings — about three seconds, so it is cheap enough to # gate a commit on. set -euo pipefail cd "$(dirname "$0")/.." TARGET="frontend/wailsjs" if [ -n "$(git status --porcelain -- "$TARGET")" ]; then echo "bindings-check: $TARGET has uncommitted changes; stage or stash them first" >&2 git status --short -- "$TARGET" >&2 exit 1 fi go tool wails generate module -tags webkit2_41 >/dev/null 2>&1 # `wails generate module` rewrites the three runtime files as 755 every # time. That is not drift, so compare content only. if ! git -c core.fileMode=false diff --quiet -- "$TARGET"; then echo "bindings-check: $TARGET is out of date with the Go bindings." >&2 echo "Run 'make bindings' and stage the result." >&2 git -c core.fileMode=false diff --stat -- "$TARGET" >&2 exit 1 fi # Restore the modes the generator churned, so the tree is left clean. chmod 644 \ frontend/wailsjs/runtime/runtime.js \ frontend/wailsjs/runtime/runtime.d.ts \ frontend/wailsjs/runtime/package.json echo "bindings-check: frontend/wailsjs is current"