verstak/scripts/build.sh

166 lines
3.9 KiB
Bash
Executable File

#!/bin/bash
set -e
# ============================================================
# Verstak build script
# Usage: ./scripts/build.sh [gui|server|extensions|all|release]
# ============================================================
BUILD_DIR="build"
# --- GUI binary ---
build_gui() {
echo "==> Building GUI binary..."
# Ensure frontend dependencies are installed
cd frontend
if [ ! -d "node_modules" ] || [ ! -f "node_modules/.package-lock.json" ]; then
echo "==> Installing frontend dependencies..."
npm install
fi
npm run build
cd ..
# Copy frontend dist to Wails embed directory
rm -rf cmd/verstak-gui/frontend-dist
mkdir -p cmd/verstak-gui/frontend-dist
cp -r frontend/dist/. cmd/verstak-gui/frontend-dist/
# Build Go binary with Wails v2
# Tags: webkit2_41 required for WebKitGTK 2.41+, desktop/production for Wails
go build -tags "webkit2_41 desktop production" -ldflags="-s -w" -o "$BUILD_DIR/verstak" ./cmd/verstak-gui/
echo "==> GUI binary: $BUILD_DIR/verstak"
}
# --- Server binary ---
build_server() {
echo "==> Building server binary..."
go build -ldflags="-s -w" -o "$BUILD_DIR/verstak-server" ./cmd/verstak-server/
echo "==> Server binary: $BUILD_DIR/verstak-server"
}
# --- Chrome extension ---
build_chrome_extension() {
echo "==> Building Chrome extension..."
local ext_dir="extension"
local out_file="$BUILD_DIR/verstak-bridge-chrome.zip"
if [ ! -d "$ext_dir" ]; then
echo "ERROR: $ext_dir/ directory not found"
return 1
fi
# Create a clean zip: manifest.json, background.js, popup/*, icons/*
cd "$ext_dir"
zip -r "../$out_file" \
manifest.json \
background.js \
popup/ \
icons/ \
-x "*/.DS_Store" "*/Thumbs.db" "*/__MACOSX/*" "*/.git/*"
cd ..
echo "==> Chrome extension: $out_file"
}
# --- Firefox extension (unsigned) ---
build_firefox_extension() {
echo "==> Building Firefox extension..."
local ext_dir="extension-firefox"
local out_file="$BUILD_DIR/verstak-bridge-firefox-unsigned.zip"
if [ ! -d "$ext_dir" ]; then
echo "ERROR: $ext_dir/ directory not found"
return 1
fi
cd "$ext_dir"
zip -r "../$out_file" \
manifest.json \
background.js \
popup/ \
icons/ \
-x "*/.DS_Store" "*/Thumbs.db" "*/__MACOSX/*" "*/.git/*"
cd ..
echo "==> Firefox extension (unsigned): $out_file"
}
# --- All extensions ---
build_extensions() {
mkdir -p "$BUILD_DIR"
build_chrome_extension
build_firefox_extension
echo "==> Extensions built."
ls -lh "$BUILD_DIR"/verstak-bridge-*
}
# --- Everything ---
build_all() {
mkdir -p "$BUILD_DIR"
build_gui
build_server
build_chrome_extension
build_firefox_extension
echo ""
echo "==> All builds complete."
ls -lh "$BUILD_DIR/"
}
# --- Release: copy to release/linux/ ---
prepare_release() {
local RELEASE_DIR="release/linux"
mkdir -p "$RELEASE_DIR"
if [ -f "$BUILD_DIR/verstak" ]; then
cp "$BUILD_DIR/verstak" "$RELEASE_DIR/verstak"
chmod 755 "$RELEASE_DIR/verstak"
echo " $RELEASE_DIR/verstak"
else
echo " WARNING: $BUILD_DIR/verstak not found, skipping"
fi
if [ -f "$BUILD_DIR/verstak-server" ]; then
cp "$BUILD_DIR/verstak-server" "$RELEASE_DIR/verstak-server"
chmod 755 "$RELEASE_DIR/verstak-server"
echo " $RELEASE_DIR/verstak-server"
else
echo " WARNING: $BUILD_DIR/verstak-server not found, skipping"
fi
}
build_release() {
echo "==> Building all + preparing release/linux/..."
build_all
prepare_release
echo ""
echo "==> Release binaries in release/linux/"
ls -lh "release/linux/"
}
# --- Main ---
case "${1:-all}" in
gui) build_gui ;;
server) build_server ;;
extensions) build_extensions ;;
chrome) mkdir -p "$BUILD_DIR"; build_chrome_extension ;;
firefox) mkdir -p "$BUILD_DIR"; build_firefox_extension ;;
release) build_release ;;
all) build_all ;;
*)
echo "Usage: $0 [gui|server|extensions|chrome|firefox|release|all]"
exit 1
;;
esac