#!/bin/sh set -eu PROJECT_DIR=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd) GODOT_BIN=${GODOT_BIN:-/Applications/Godot.app/Contents/MacOS/Godot} WEB_DIR="$PROJECT_DIR/build/web" PACK_DIR="$WEB_DIR/packs" if [ ! -x "$GODOT_BIN" ]; then echo "Godot executable not found: $GODOT_BIN" >&2 exit 1 fi mkdir -p "$WEB_DIR" "$PACK_DIR" find "$PACK_DIR" -maxdepth 1 -type f \( -name '*.pck' -o -name 'manifest.json' \) -delete "$GODOT_BIN" --headless --path "$PROJECT_DIR" --export-release "Web" "$WEB_DIR/index.html" build_pack() { pack_key=$1 preset=$2 temp_path="$PACK_DIR/$pack_key.pck" "$GODOT_BIN" --headless --path "$PROJECT_DIR" --export-pack "$preset" "$temp_path" >&2 hash=$(shasum -a 256 "$temp_path" | awk '{print substr($1, 1, 12)}') file_name="$pack_key-$hash.pck" mv "$temp_path" "$PACK_DIR/$file_name" size=$(stat -f '%z' "$PACK_DIR/$file_name") jq -n --arg file "$file_name" --argjson size "$size" '{file: $file, size: $size}' } square=$(build_pack "square" "Scene Square") work_zone=$(build_pack "work_zone" "Scene Work Zone") cafe=$(build_pack "cafe_interior" "Scene Cafe") personal_space=$(build_pack "personal_space" "Scene Personal Space") auth=$(build_pack "auth" "Scene Auth") jq -n \ --argjson square "$square" \ --argjson work_zone "$work_zone" \ --argjson cafe_interior "$cafe" \ --argjson personal_space "$personal_space" \ --argjson auth "$auth" \ '{version: 1, packs: {auth: $auth, square: $square, work_zone: $work_zone, cafe_interior: $cafe_interior, personal_space: $personal_space}}' \ > "$PACK_DIR/manifest.json" cp "$PROJECT_DIR/web/auth-background.jpg" "$WEB_DIR/auth-background.jpg" echo "Progressive web build created in $WEB_DIR" du -h "$WEB_DIR/index.pck" "$WEB_DIR/index.wasm" "$WEB_DIR/auth-background.jpg" "$PACK_DIR"/*.pck