#!/usr/bin/env bash # Builds www/ from reference/ for the Capacitor wrapper. # # reference/ is the frozen spec and is NEVER edited. Everything native-specific # is either an additive file (native.css, native.js) or one of the three # removals below. Each patch asserts its anchor exists, so if the reference # ever changes shape this fails loudly instead of silently shipping a broken app. set -euo pipefail cd "$(dirname "$0")/.." SRC="reference" OUT="www" [ -f "$SRC/index.html" ] || { echo "missing $SRC/index.html"; exit 1; } rm -rf "$OUT" mkdir -p "$OUT" # sw.js and README.md are deliberately not copied: # - the service worker would cache index.html and serve a stale app after an # APK update; assets are already local so it buys nothing. # - README documents the web deployment, irrelevant inside the APK. cp -r "$SRC/fonts" "$SRC/icons" "$OUT/" cp "$SRC/manifest.webmanifest" "$OUT/" # harmless, keeps icon refs valid cp "$SRC/index.html" "$OUT/index.html" cp native/native.css native/native.js "$OUT/" python3 - "$OUT/index.html" <<'PY' import sys, re path = sys.argv[1] html = open(path, encoding="utf-8").read() def patch(html, anchor, replacement, label): if anchor not in html: sys.exit(f"sync-www: anchor not found for '{label}':\n {anchor[:90]}") return html.replace(anchor, replacement, 1) # 1. drop the service worker registration sw = '\n' html = patch(html, sw, "", "service worker registration") # 2. drop the web manifest link (the APK's own manifest governs the app) html = patch(html, '', "", "manifest link") # 3. native stylesheet last in so its overrides win on equal specificity html = patch(html, "", '\n', "head close") # 4. native script after the app script, so its globals already exist html = patch(html, "", '\n', "body close") open(path, "w", encoding="utf-8").write(html) print("sync-www: patched index.html (4/4 anchors matched)") PY echo "sync-www: $OUT/ built from $SRC/"