forked from projectM-visualizer/projectm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptimize.sh
More file actions
57 lines (45 loc) · 1.78 KB
/
optimize.sh
File metadata and controls
57 lines (45 loc) · 1.78 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
#!/bin/bash
set -e # Exit on error for critical operations
echo "🚀 Starting Post-Build Optimization..."
# 1. Define Paths
NATIVE_WASM="/content/build_space/projectm/projectm-v.024-thread.wasm"
# 2. Check for Tools (but don't fail if missing)
WASM_OPT_AVAILABLE=false
TERSER_AVAILABLE=false
if command -v wasm-opt &> /dev/null; then
WASM_OPT_AVAILABLE=true
echo "✓ wasm-opt found"
else
echo "⚠️ wasm-opt not found - skipping WASM optimization"
fi
if command -v terser &> /dev/null; then
TERSER_AVAILABLE=true
echo "✓ terser found"
else
echo "⚠️ terser not found - skipping JS minification"
fi
if ! command -v wasmedge &> /dev/null; then
echo "⚠️ wasmedge not found! Installing via 'curl -sSf https://raw.githubusercontent.com/WasmEdge/WasmEdge/master/utils/install.sh | bash && source $HOME/.wasmedge/env'"
curl -sSf https://raw.githubusercontent.com/WasmEdge/WasmEdge/master/utils/install.sh | bash && source $HOME/.wasmedge/env
fi
if ! command -v wasmedge &> /dev/null; then
echo "⚠️ wasmedge still not found!"
else
WASMEDGE_AVAILABLE=true
echo "✓ wasmedge found"
fi
# Try wasmedge optimization if available
if [ "$WASMEDGE_AVAILABLE" = true ] && [ -f "$NATIVE_WASM" ]; then
echo "🔧 Optimizing WASM (wasmedge)..."
wasmedgec --optimize=3 --enable-all "$NATIVE_WASM" "$NATIVE_WASM" || true
fi
# 5. Minify Emscripten Loaders (Safety First) - commented out as files may not exist
#if [ "$TERSER_AVAILABLE" = true ] && [ -f "$NATIVE_JS" ]; then
# echo "📦 Minifying JS Loaders..."
# terser "$NATIVE_JS" -o "$NATIVE_JS" \
# --compress defaults=false,dead_code=true,unused=true,loops=true,conditionals=true \
# --mangle reserved=['Module','FS','GL'] \
# --comments false
#fi
echo "✅ Optimization Complete!"
exit 0