-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·114 lines (95 loc) · 2.82 KB
/
build.sh
File metadata and controls
executable file
·114 lines (95 loc) · 2.82 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/bin/bash
# Exit on any error
set -e
# Function to check if a command exists
command_exists () {
command -v "$1" >/dev/null 2>&1
}
# Default mode is release for smaller, production-ready builds
MODE=${1:-release}
# Validate mode
if [[ "$MODE" != "debug" && "$MODE" != "release" ]]; then
echo "Error: Invalid mode. Use 'debug' or 'release'."
exit 1
fi
# Check dependencies
missing_deps=0
# Check for Node.js
if ! command_exists node; then
missing_deps=1
echo "❌ Node.js is not installed."
echo ""
echo "To install Node.js, visit the official download page:"
echo "👉 https://nodejs.org/en/download/"
echo ""
echo "Or install it using a package manager:"
echo ""
echo "🔹 macOS (Homebrew):"
echo " brew install node"
echo ""
echo "🔹 Ubuntu/Debian:"
echo " sudo apt-get install -y nodejs npm"
echo ""
echo "🔹 Arch Linux:"
echo " sudo pacman -S nodejs npm"
echo ""
fi
# Check for npm
if ! command_exists npm; then
missing_deps=1
echo "❌ npm is not installed."
echo ""
echo "npm is typically included with Node.js."
echo "If you have Node.js but not npm, please reinstall Node.js."
echo ""
fi
# Exit with a bad exit code if any dependencies are missing
if [ "$missing_deps" -ne 0 ]; then
echo "Install the missing dependencies and ensure they are on your path. Then run this command again."
exit 1
fi
# Check if package.json exists
if [ ! -f "package.json" ]; then
echo "Error: No package.json found. Please run this script in the JavaScript project directory."
exit 1
fi
# Check if wit directory exists
if [ ! -d "wit" ]; then
echo "Error: No wit directory found. Please ensure the WIT interface definitions are present."
exit 1
fi
# Check if app.js exists
if [ ! -f "app.js" ]; then
echo "Error: No app.js found. Please ensure the main component file is present."
exit 1
fi
# Install dependencies if node_modules doesn't exist
if [ ! -d "node_modules" ]; then
echo "Installing Node.js dependencies..."
npm install
else
echo "✅ Node.js dependencies already installed"
fi
# Fetch WIT dependencies using wkg
echo "Fetching WIT dependencies..."
wkg wit fetch
# Clean any previous build artifacts
echo "Cleaning previous build artifacts..."
rm -rf dist/
mkdir -p dist
# Build the JavaScript component to WASM using ComponentizeJS
echo "Building JavaScript component to WASM..."
# Use ComponentizeJS to build the WASM component
# The npx command will use the locally installed version from package.json
npx jco componentize \
-w wit/ \
-o dist/plugin.wasm \
app.js
# Check if the generated .wasm file exists
if [ ! -f "dist/plugin.wasm" ]; then
echo "Error: WASM file generation failed"
exit 1
fi
echo "✓ Build complete. WASM component created at dist/plugin.wasm"
# Show file size
echo "File size: $(du -h dist/plugin.wasm | cut -f1)"