Files
overlord/scripts/build-prod-package.sh
T

99 lines
2.6 KiB
Bash
Raw Normal View History

2026-03-05 00:04:26 -06:00
#!/usr/bin/env bash
set -euo pipefail
2026-06-12 09:14:49 -05:00
SCRIPT_DIR="$(cd -- "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
ROOT="$(cd -- "$SCRIPT_DIR/.." && pwd)"
2026-03-05 00:04:26 -06:00
SERVER_SRC="$ROOT/Overlord-Server"
CLIENT_SRC="$ROOT/Overlord-Client"
DIST_CLIENTS_SRC="$ROOT/dist-clients"
RELEASE_DIR="$ROOT/release/prod-package"
if [[ ! -f "$SERVER_SRC/package.json" ]]; then
echo "[error] Overlord-Server not found at: $SERVER_SRC" >&2
exit 1
fi
if [[ ! -f "$CLIENT_SRC/go.mod" ]]; then
echo "[error] Overlord-Client not found at: $CLIENT_SRC" >&2
exit 1
fi
if ! command -v bun >/dev/null 2>&1; then
echo "[error] bun was not found in PATH." >&2
exit 1
fi
if ! command -v go >/dev/null 2>&1; then
echo "[error] go was not found in PATH." >&2
exit 1
fi
copy_tree_excluding() {
local src="$1"
local dst="$2"
shift 2
mkdir -p "$dst"
if command -v rsync >/dev/null 2>&1; then
local excludes=()
for pattern in "$@"; do
excludes+=(--exclude "$pattern")
done
rsync -a --delete "${excludes[@]}" "$src/" "$dst/"
else
local tar_excludes=()
for pattern in "$@"; do
tar_excludes+=("--exclude=$pattern")
done
(cd "$src" && tar "${tar_excludes[@]}" -cf - .) | (cd "$dst" && tar -xf -)
fi
}
echo "[1/5] Building server bundle..."
pushd "$SERVER_SRC" >/dev/null
bun install
bun run build:css
bun run build
popd >/dev/null
echo "[2/5] Skipping prebuilt client binaries (prod package exports client source only)"
echo "[3/5] Preparing release folder..."
rm -rf "$RELEASE_DIR"
mkdir -p "$RELEASE_DIR"
echo "[4/5] Exporting Overlord-Server..."
copy_tree_excluding "$SERVER_SRC" "$RELEASE_DIR/Overlord-Server" "node_modules" ".git" ".vscode"
echo "[5/5] Exporting Overlord-Client source for runtime builds..."
copy_tree_excluding "$CLIENT_SRC" "$RELEASE_DIR/Overlord-Client" "build" ".git" ".vscode"
if [[ -d "$DIST_CLIENTS_SRC" ]]; then
echo "[extra] Copying prebuilt dist-clients..."
mkdir -p "$RELEASE_DIR/dist-clients"
cp -a "$DIST_CLIENTS_SRC/." "$RELEASE_DIR/dist-clients/"
fi
cat > "$RELEASE_DIR/start-prod-release.sh" <<'EOF'
#!/usr/bin/env bash
set -euo pipefail
ROOT="$(cd -- "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$ROOT/Overlord-Server"
export HOST="${HOST:-0.0.0.0}"
export PORT="${PORT:-5173}"
export LOG_LEVEL="${LOG_LEVEL:-info}"
export NODE_ENV="${NODE_ENV:-production}"
bun install
bun run build:css && bun run vendor
bun run minify
bun run src/index.ts
2026-03-05 00:04:26 -06:00
EOF
chmod +x "$RELEASE_DIR/start-prod-release.sh"
echo
echo "[ok] Production package created:"
echo " $RELEASE_DIR"
echo
echo "Run this from the package folder:"
echo " ./start-prod-release.sh"