-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-web.sh
More file actions
executable file
·87 lines (76 loc) · 3.37 KB
/
Copy pathbuild-web.sh
File metadata and controls
executable file
·87 lines (76 loc) · 3.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/env bash
# Build Bloom Jump for the web.
#
# Output: dist/web/
# index.html Perry-generated game HTML, post-processed to boot via bloom_ffi.js
# bloom_ffi.js Orchestrator: loads bloom_web, wires __ffiImports, calls bootPerryWasm
# pkg/ bloom_web wasm-bindgen output (rebuilt from ../engine/native/web)
# assets/ game sprites, sounds, levels (copied from ./assets)
#
# Flags:
# --skip-bloom Reuse existing ../engine/native/web/pkg/ (skip wasm-pack)
# --serve After build, launch `python3 -m http.server 8080` in dist/web
set -euo pipefail
JUMP_DIR="$(cd "$(dirname "$0")" && pwd)"
# Build bloom_web from the SAME engine the game compiles against (node_modules),
# so the runtime glue and the game WASM's FFI ABI never skew. Falls back to a
# sibling engine source checkout (../engine) for local engine development.
BLOOM_WEB="$JUMP_DIR/node_modules/@bloomengine/engine/native/web"
[ -d "$BLOOM_WEB" ] || BLOOM_WEB="$JUMP_DIR/../engine/native/web"
OUT="$JUMP_DIR/dist/web"
skip_bloom=false
serve=false
for arg in "$@"; do
case "$arg" in
--skip-bloom) skip_bloom=true ;;
--serve) serve=true ;;
-h|--help) sed -n '2,15p' "$0"; exit 0 ;;
*) echo "unknown flag: $arg" >&2; exit 2 ;;
esac
done
if [ ! -d "$BLOOM_WEB" ]; then
echo "error: bloom web crate not found at $BLOOM_WEB" >&2
exit 1
fi
if ! $skip_bloom; then
echo "[1/4] Building bloom_web.wasm (wasm-pack release)..."
(cd "$BLOOM_WEB" && wasm-pack build --target web --out-dir pkg --no-typescript --release 2>&1 | tail -3)
else
echo "[1/4] Skipping bloom_web build (--skip-bloom)"
fi
# Newer Perry (0.5.x) rejects the engine's web native-library target unless it
# declares `crate`+`lib` or `prebuilt`; the published engine ships the old
# `crate`/`output` schema, so an unpatched `perry compile --target web` fails
# with "crate and lib must be declared together". Patch the (gitignored)
# node_modules manifest in place — the file perry actually reads — before
# compiling. Idempotent; node_modules is rebuilt by `npm ci`, never committed.
node "$JUMP_DIR/store/tools/patch_engine_web.js"
echo "[2/4] Compiling game WASM (perry --target web)..."
rm -rf "$OUT"
mkdir -p "$OUT"
perry compile --target web "$JUMP_DIR/src/main.ts" -o "$OUT/game" >/dev/null
echo "[3/4] Assembling dist/web..."
cp -R "$BLOOM_WEB/pkg" "$OUT/pkg"
cp -R "$JUMP_DIR/assets" "$OUT/assets"
cp "$JUMP_DIR/web/bloom_ffi.js" "$OUT/bloom_ffi.js"
# Post-process Perry's self-contained HTML:
# - The file already sets `window.__perryWasmB64 = "..."` as a global.
# - It then calls `bootPerryWasm("...big base64...").catch(...)` inline.
# - We neutralize that inline call (defined but not invoked) and insert
# `<canvas id="bloom-canvas">` plus a `<script type="module" src="./bloom_ffi.js">`
# so bloom_ffi.js owns the boot sequence.
python3 "$JUMP_DIR/tools/wire-web-html.py" "$OUT/game.html" "$OUT/index.html"
rm "$OUT/game.html"
echo "[4/4] Done."
WASM_KB=$(($(wc -c < "$OUT/pkg/bloom_web_bg.wasm") / 1024))
HTML_KB=$(($(wc -c < "$OUT/index.html") / 1024))
ASSETS_KB=$(du -sk "$OUT/assets" | cut -f1)
echo " bloom_web.wasm: ${WASM_KB}KB"
echo " index.html: ${HTML_KB}KB"
echo " assets/: ${ASSETS_KB}KB"
echo ""
echo "Serve: (cd $OUT && python3 -m http.server 8080)"
echo "Open: http://localhost:8080"
if $serve; then
(cd "$OUT" && exec python3 -m http.server 8080)
fi