#!/usr/bin/env bash set -euo pipefail # Pass --production (or set PROTOKILL_PRODUCTION=1) for a release deploy; it # hides the dev build stamp. Without it, this is treated as a preview build. PRODUCTION="${PROTOKILL_PRODUCTION:-0}" case "${1:-}" in --production) PRODUCTION=1 ;; "") ;; *) echo "usage: $0 [--production]" >&2; exit 2 ;; esac # Source cargo environment (needed when rustup was installed in a prior CI phase). [[ -f "$HOME/.cargo/env" ]] && source "$HOME/.cargo/env" REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" DEST="$REPO_ROOT/output" BUNDLE="$REPO_ROOT/target/bevy_web/web-release/protokill_wasm_frontend" FONTS_DIR="$REPO_ROOT/crates/protokill_wasm_frontend/assets/fonts/.fetched" if [[ "$PRODUCTION" == "1" ]]; then capture_mode=production else capture_mode=dev fi # shellcheck source=build-stamp.sh source "$REPO_ROOT/scripts/build-stamp.sh" capture_build_stamp "$capture_mode" build_info_json > "$REPO_ROOT/web/build-info.json" export_build_stamp echo "==> Fetching terminal fonts" "$REPO_ROOT/scripts/fetch-fonts.sh" echo "==> Building ATProto JS bundle" (cd "$REPO_ROOT/web" && npm install --silent && npm run build) echo "==> Building WASM app" cd "$REPO_ROOT" bevy build --yes --release -p protokill_wasm_frontend web --bundle echo "==> Assembling output" rm -rf "$DEST" mkdir -p "$DEST" cp -r "$BUNDLE/." "$DEST/" rm -rf "$DEST/node_modules" "$DEST/package.json" "$DEST/package-lock.json" # Copy static assets not included in the bevy bundle. # Note: static/index.html is the pre-launch placeholder — the real # index.html comes from web/index.html via the bevy bundle above. cp "$REPO_ROOT/static/favicon.ico" "$DEST/" cp "$REPO_ROOT/static/client-metadata.json" "$DEST/" cp "$REPO_ROOT/static/privacy.html" "$DEST/" cp "$REPO_ROOT/static/client-metadata-preview.json" "$DEST/" # The fonts are fetched, so ship their upstream licences beside them. for licence in "$FONTS_DIR"/*/*.txt; do face="$(basename "$(dirname "$licence")")" mkdir -p "$DEST/fonts/$face" cp "$licence" "$DEST/fonts/$face/" done # Precompress the wasm. Amplify uploads every artifact (`**/*` in amplify.yml), # so the files are available at `.wasm.br`/`.gz`; serving them for # `.wasm` still needs a custom-header or rewrite rule in the Amplify # console. `brotli` is not in every build image, so fall back to Node's zlib, # which the `npm install` above guarantees. WASM="$DEST/build/protokill_wasm_frontend_bg.wasm" if command -v brotli >/dev/null 2>&1; then brotli --quality=11 --force "$WASM" else node -e ' const fs = require("node:fs"); const zlib = require("node:zlib"); const file = process.argv[1]; const input = fs.readFileSync(file); fs.writeFileSync(file + ".br", zlib.brotliCompressSync(input, { params: { [zlib.constants.BROTLI_PARAM_QUALITY]: 11, [zlib.constants.BROTLI_PARAM_SIZE_HINT]: input.length, }, })); ' "$WASM" fi echo "Precompressed $WASM.br" gzip --best --force --keep --no-name "$WASM" echo "Precompressed $WASM.gz" echo "Deployed to $DEST"