groupchat/dev.sh
Jason Tudisco 1c7d4d0510 feat: add production deployment and macOS dev scripts
Add dev.sh for running server + client in parallel on macOS, and prod.sh
for building and deploying in production. The Rust server now serves
static client files with SPA fallback, eliminating the need for Vite in
production. Also adds missing BRAVE_API_KEY to .env.example.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 07:27:06 -06:00

72 lines
1.8 KiB
Bash
Executable File

#!/usr/bin/env bash
# GroupChat2 Dev Script (macOS/Linux)
# Runs both server (Rust/Axum) and client (Vite) with unified console output.
# Ctrl+C stops both processes.
set -e
ROOT="$(cd "$(dirname "$0")" && pwd)"
# Colors
MAGENTA='\033[0;35m'
YELLOW='\033[0;33m'
CYAN='\033[0;36m'
RED='\033[0;31m'
GRAY='\033[0;90m'
NC='\033[0m'
# Install client deps if needed
if [ ! -d "$ROOT/client/node_modules" ]; then
echo -e "${CYAN}[dev] Installing client dependencies...${NC}"
(cd "$ROOT/client" && npm install)
fi
echo ""
echo -e " ${MAGENTA}GroupChat2 Dev Server${NC}"
echo -e " ${YELLOW}Server: http://localhost:3001${NC}"
echo -e " ${CYAN}Client: http://localhost:3000${NC}"
echo -e " ${GRAY}Press Ctrl+C to stop both${NC}"
echo ""
# Track child PIDs for cleanup
SERVER_PID=""
CLIENT_PID=""
cleanup() {
echo ""
echo -e "${RED}[dev] Shutting down...${NC}"
# Kill background jobs
[ -n "$SERVER_PID" ] && kill "$SERVER_PID" 2>/dev/null
[ -n "$CLIENT_PID" ] && kill "$CLIENT_PID" 2>/dev/null
# Kill any lingering processes on ports 3000/3001
lsof -ti:3000 2>/dev/null | xargs kill -9 2>/dev/null || true
lsof -ti:3001 2>/dev/null | xargs kill -9 2>/dev/null || true
# Kill groupchat-server if still running
pkill -f "groupchat-server" 2>/dev/null || true
echo -e "${RED}[dev] Stopped.${NC}"
exit 0
}
trap cleanup INT TERM
# Start server (Rust/Axum)
(cd "$ROOT/server" && cargo run 2>&1 | while IFS= read -r line; do
[ -n "$line" ] && echo -e "${YELLOW}[server]${NC} $line"
done) &
SERVER_PID=$!
# Start client (Vite)
(cd "$ROOT/client" && npm run dev 2>&1 | while IFS= read -r line; do
[ -n "$line" ] && echo -e "${CYAN}[client]${NC} $line"
done) &
CLIENT_PID=$!
# Wait for either to exit
wait -n "$SERVER_PID" "$CLIENT_PID" 2>/dev/null
echo -e "${RED}[dev] A process exited unexpectedly.${NC}"
cleanup