forked from WofWca/quake3.xdc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·90 lines (77 loc) · 3.13 KB
/
build.sh
File metadata and controls
executable file
·90 lines (77 loc) · 3.13 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
88
89
90
#!/bin/bash
# Build script for VectorQuake WebXDC package
# Creates VectorQuake.xdc with minified files for production
cd "$(dirname "$0")"
# Remove old package if exists
rm -f ../VectorQuake.xdc
# Create a temporary build directory
BUILD_DIR=$(mktemp -d)
trap "rm -rf $BUILD_DIR" EXIT
# Whitelist: only copy files needed for the .xdc
echo "Copying files to build directory..."
cp index.html main-menu.html manifest.toml icon.png "$BUILD_DIR/"
cp ioquake3_opengl2.wasm32.js ioquake3_opengl2.wasm32.wasm "$BUILD_DIR/"
cp demoq3-pak0.pk3 pak1-fix-demo-bots.pk3 ztm-flexible-hud.pk3 "$BUILD_DIR/"
cp GamepadEmulator.js override-webrtc.js override-websocket-signaling.js "$BUILD_DIR/"
cp compression-streams-polyfill.0.1.7.js "$BUILD_DIR/"
cp emscripten-fs-file-explorer-ui.iife.js "$BUILD_DIR/"
cp webxdc-download-polyfill.js "$BUILD_DIR/"
# License files stay in the repo but are excluded from the .xdc build
# (source_code_url in manifest.toml links to the repo with full licenses)
# Minify JavaScript files using terser
if command -v npx &> /dev/null && npx terser --version &> /dev/null 2>&1; then
echo "Minifying JavaScript..."
# Minify standalone JS files in parallel
for file in \
"$BUILD_DIR/GamepadEmulator.js" \
"$BUILD_DIR/override-webrtc.js" \
"$BUILD_DIR/override-websocket-signaling.js" \
"$BUILD_DIR/webxdc-download-polyfill.js" \
"$BUILD_DIR/emscripten-fs-file-explorer-ui.iife.js" \
"$BUILD_DIR/compression-streams-polyfill.0.1.7.js"
do
if [ -f "$file" ]; then
# Check if file has ES6 exports/imports for module mode
if grep -q "^export \|^import " "$file"; then
npx terser "$file" --module --compress --mangle -o "$file.tmp" && mv "$file.tmp" "$file" &
else
npx terser "$file" --compress --mangle -o "$file.tmp" && mv "$file.tmp" "$file" &
fi
fi
done
# The big one: minify ioquake3 Emscripten JS runtime (~580KB)
npx terser "$BUILD_DIR/ioquake3_opengl2.wasm32.js" \
--compress --mangle -o "$BUILD_DIR/ioquake3_opengl2.wasm32.js.tmp" \
&& mv "$BUILD_DIR/ioquake3_opengl2.wasm32.js.tmp" "$BUILD_DIR/ioquake3_opengl2.wasm32.js" &
wait
echo "JavaScript minified."
else
echo "WARNING: terser not found, skipping JS minification"
echo " Install with: npm install -g terser"
fi
# Minify HTML files (remove comments, whitespace, empty lines)
echo "Minifying HTML..."
for htmlfile in "$BUILD_DIR/index.html" "$BUILD_DIR/main-menu.html"; do
if [ -f "$htmlfile" ]; then
perl -0777 -pe '
# Remove HTML comments (but not IE conditionals)
s/<!--(?!\[).*?-->//gs;
# Remove leading/trailing whitespace from lines
s/^\s+//gm;
s/\s+$//gm;
# Remove empty lines
s/\n\s*\n/\n/g;
' "$htmlfile" > "$htmlfile.min" && mv "$htmlfile.min" "$htmlfile"
fi
done
# Remove .DS_Store if any snuck in
find "$BUILD_DIR" -name ".DS_Store" -delete
# Create zip with maximum compression
echo "Packaging VectorQuake.xdc..."
cd "$BUILD_DIR"
zip -9 -r "$OLDPWD/../VectorQuake.xdc" .
echo ""
echo "Built VectorQuake.xdc"
echo "Size: $(du -h "$OLDPWD/../VectorQuake.xdc" | cut -f1)"
echo ""
echo "Send VectorQuake.xdc to a Vector or Delta Chat conversation to play!"