forked from JSKitty/VectorDoom
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-xdc.sh
More file actions
executable file
·84 lines (67 loc) · 2.38 KB
/
build-xdc.sh
File metadata and controls
executable file
·84 lines (67 loc) · 2.38 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
#!/bin/bash
# VectorDoom WebXDC Build Script
# Packages the compiled DOOM WASM + assets into a .xdc file
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
# Remove old build
rm -f vectordoom.xdc
# Create staging directory
rm -rf _xdc_staging
mkdir -p _xdc_staging
# Copy built files
cp src/vector-doom.js _xdc_staging/vector-doom.js
cp src/vector-doom.wasm _xdc_staging/vector-doom.wasm
cp src/webxdc-net.js _xdc_staging/webxdc-net.js
cp src/index.html _xdc_staging/index.html
cp src/doom1.wad _xdc_staging/doom1.wad
cp src/default.cfg _xdc_staging/default.cfg
cp src/bg.jpg _xdc_staging/bg.jpg
cp manifest.toml _xdc_staging/manifest.toml
# Create icon if it doesn't exist
if [ ! -f icon.png ]; then
cat > _xdc_staging/icon.svg << 'ICONEOF'
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 128 128">
<rect width="128" height="128" fill="#1a0000"/>
<text x="64" y="78" text-anchor="middle" font-family="monospace" font-weight="bold" font-size="36" fill="#cc0000">DOOM</text>
</svg>
ICONEOF
else
cp icon.png _xdc_staging/icon.png
fi
# === OPTIMIZATION ===
# JS minification with terser (parallel)
if command -v npx &> /dev/null && npx terser --version &> /dev/null 2>&1; then
echo "Minifying JS with terser..."
ORIG_ENGINE=$(wc -c < _xdc_staging/vector-doom.js | tr -d ' ')
# Emscripten runtime (biggest win)
npx terser _xdc_staging/vector-doom.js --compress --mangle -o _xdc_staging/vector-doom.js &
PID1=$!
# Networking layer
npx terser _xdc_staging/webxdc-net.js --compress --mangle -o _xdc_staging/webxdc-net.js &
PID2=$!
wait $PID1 $PID2
NEW_ENGINE=$(wc -c < _xdc_staging/vector-doom.js | tr -d ' ')
echo " vector-doom.js: ${ORIG_ENGINE} -> ${NEW_ENGINE} bytes ($(( 100 - NEW_ENGINE * 100 / ORIG_ENGINE ))% reduction)"
else
echo "WARNING: terser not found, skipping JS minification (npm i -g terser)"
fi
# HTML minification (strip comments, whitespace)
echo "Minifying HTML..."
perl -0777 -pe '
s/<!--(?!\[).*?-->//gs;
s/^\s+//gm;
s/\s+$//gm;
s/\n\n+/\n/g;
' _xdc_staging/index.html > _xdc_staging/index.html.min
mv _xdc_staging/index.html.min _xdc_staging/index.html
# Cleanup
rm -f _xdc_staging/.DS_Store
# Package as .xdc with max compression
cd _xdc_staging
zip -9 -r ../vectordoom.xdc . -x ".*"
cd ..
# Cleanup
rm -rf _xdc_staging
echo ""
echo "Build complete: vectordoom.xdc"
ls -lah vectordoom.xdc