Fantasy-Map-Generator/scripts/pre-push

29 lines
1 KiB
Bash
Executable file

#!/usr/bin/env sh
# Git pre-push hook — automatically bumps the version before pushing.
# Installed by: npm run prepare (scripts/install-hooks.js)
#
# Prompts for patch / minor / major (default: patch), updates:
# - public/versioning.js
# - package.json
# - src/index.html (cache-busting ?v= hashes for changed modules)
# then commits those changes so they are included in the push.
set -e
REPO_ROOT="$(git rev-parse --show-toplevel)"
echo ""
node "$REPO_ROOT/scripts/bump-version.js"
# Stage files that may have been modified by the bump
git add \
"$REPO_ROOT/public/versioning.js" \
"$REPO_ROOT/package.json" \
"$REPO_ROOT/src/index.html" 2>/dev/null || true
# Only commit if there are staged changes from the bump
if ! git diff --cached --quiet; then
NEW_VERSION=$(node -e "const f=require('fs');const m=f.readFileSync('$REPO_ROOT/public/versioning.js','utf8').match(/const VERSION = \"([\d.]+)\"/);console.log(m[1])")
git commit -m "chore: bump version to $NEW_VERSION"
echo "[pre-push] Committed version bump → $NEW_VERSION"
fi