-
Notifications
You must be signed in to change notification settings - Fork 355
Expand file tree
/
Copy pathbundle-wasm-docs.sh
More file actions
executable file
·53 lines (46 loc) · 1.9 KB
/
bundle-wasm-docs.sh
File metadata and controls
executable file
·53 lines (46 loc) · 1.9 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
#!/usr/bin/env bash
#
# bundle-wasm-docs.sh -- Build the WebAssembly compiler and copy
# artifacts into the Astro docs site's public directory.
#
# Usage:
# ./scripts/bundle-wasm-docs.sh
#
set -euo pipefail
REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)"
DEST_DIR="${REPO_ROOT}/docs/public/wasm"
echo "==> Building gh-aw.wasm..."
cd "${REPO_ROOT}"
make build-wasm
echo "==> Copying artifacts to ${DEST_DIR}..."
mkdir -p "${DEST_DIR}"
cp "${REPO_ROOT}/gh-aw.wasm" "${DEST_DIR}/gh-aw.wasm"
# wasm_exec.js ships with the Go toolchain; try both known locations then fall back to repo-root copy.
WASM_EXEC_SRC="$(go env GOROOT)/misc/wasm/wasm_exec.js"
if [ ! -f "${WASM_EXEC_SRC}" ]; then
# Go 1.24+ moved wasm_exec.js to lib/wasm/
WASM_EXEC_SRC="$(go env GOROOT)/lib/wasm/wasm_exec.js"
fi
if [ ! -f "${WASM_EXEC_SRC}" ]; then
# Search the Go module cache as a fallback
WASM_EXEC_SRC="$(find "$(go env GOPATH)/pkg/mod" -name wasm_exec.js -path "*/go1.*/lib/wasm/*" 2>/dev/null | sort -V | tail -1)"
fi
if [ ! -f "${WASM_EXEC_SRC}" ]; then
WASM_EXEC_SRC="${REPO_ROOT}/wasm_exec.js"
fi
cp "${WASM_EXEC_SRC}" "${DEST_DIR}/wasm_exec.js"
# Generate brotli-compressed version for smaller transfers
# GitHub Pages serves .br files automatically when Accept-Encoding: br is present
if command -v brotli &> /dev/null; then
echo "==> Compressing WASM with brotli..."
brotli -k -q 11 "${DEST_DIR}/gh-aw.wasm"
echo "Compressed: $(du -h "${DEST_DIR}/gh-aw.wasm.br" | cut -f1) (from $(du -h "${DEST_DIR}/gh-aw.wasm" | cut -f1))"
else
echo "Warning: brotli not found. Install with: apt-get install brotli (or brew install brotli)"
echo "Falling back to gzip compression..."
gzip -k -9 "${DEST_DIR}/gh-aw.wasm"
echo "Compressed: $(du -h "${DEST_DIR}/gh-aw.wasm.gz" | cut -f1) (from $(du -h "${DEST_DIR}/gh-aw.wasm" | cut -f1))"
fi
echo ""
echo "Done. Files in ${DEST_DIR}:"
ls -lh "${DEST_DIR}/gh-aw.wasm" "${DEST_DIR}/wasm_exec.js"