30 lines
1008 B
Bash
Executable File
30 lines
1008 B
Bash
Executable File
#!/usr/bin/env bash
|
|
# After flutter build web: bust CDN/browser cache for bootstrap + main.dart.js.
|
|
set -euo pipefail
|
|
|
|
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
WEB="$ROOT/build/web"
|
|
INDEX="$WEB/index.html"
|
|
BOOT="$WEB/flutter_bootstrap.js"
|
|
|
|
if [ ! -f "$INDEX" ]; then
|
|
echo "Missing $INDEX — run flutter build web first." >&2
|
|
exit 1
|
|
fi
|
|
|
|
STAMP="$(git -C "$ROOT" rev-parse --short HEAD 2>/dev/null || echo nogit)-$(date +%Y%m%d%H%M%S)"
|
|
echo "Web cache-bust stamp: $STAMP"
|
|
|
|
# index.html: versioned bootstrap URL (index.html is no-cache at origin).
|
|
if grep -q 'flutter_bootstrap.js' "$INDEX"; then
|
|
sed -i "s|flutter_bootstrap.js[^\"']*|flutter_bootstrap.js?v=${STAMP}|g" "$INDEX"
|
|
fi
|
|
|
|
# flutter_bootstrap.js: versioned main.dart.js load path in buildConfig.
|
|
if [ -f "$BOOT" ]; then
|
|
sed -i "s|\"mainJsPath\":\"main.dart.js\"|\"mainJsPath\":\"main.dart.js?v=${STAMP}\"|g" "$BOOT"
|
|
fi
|
|
|
|
printf '%s\n' "$STAMP" >"$WEB/BUILD_STAMP.txt"
|
|
echo "Stamped: $INDEX and flutter_bootstrap.js (if present)"
|