-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdev.sh
More file actions
executable file
·86 lines (68 loc) · 3.05 KB
/
dev.sh
File metadata and controls
executable file
·86 lines (68 loc) · 3.05 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
#!/usr/bin/env bash
set -euo pipefail
# ──────────────────────────────────────────────
# Calendar Assistant — local dev launcher
# Starts backend (Express) and frontend (Vite) concurrently.
# ──────────────────────────────────────────────
ROOT_DIR="$(cd "$(dirname "$0")" && pwd)"
BACKEND_DIR="$ROOT_DIR/backend"
FRONTEND_DIR="$ROOT_DIR/app"
# Colours
RED='\033[0;31m'
GREEN='\033[0;32m'
CYAN='\033[0;36m'
NC='\033[0m' # No colour
log() { echo -e "${CYAN}[dev]${NC} $*"; }
err() { echo -e "${RED}[dev]${NC} $*" >&2; }
# ── Pre-flight checks ────────────────────────
if ! command -v node &>/dev/null; then
err "node is not installed. Install Node.js >= 18."
exit 1
fi
if ! command -v mongod &>/dev/null && ! command -v mongosh &>/dev/null; then
log "${RED}Warning:${NC} MongoDB doesn't appear to be installed locally."
log "Make sure a MongoDB instance is reachable at the URI in your .env.dev.local"
fi
if [ ! -f "$BACKEND_DIR/.env.dev.local" ]; then
err "Missing $BACKEND_DIR/.env.dev.local"
err "Copy .env.dev.local.example and fill in your credentials:"
err " cp $BACKEND_DIR/.env.dev.local.example $BACKEND_DIR/.env.dev.local"
exit 1
fi
# ── Install dependencies if needed ───────────
install_if_needed() {
local dir="$1" name="$2"
if [ ! -d "$dir/node_modules" ]; then
log "Installing $name dependencies..."
(cd "$dir" && npm install)
fi
}
install_if_needed "$BACKEND_DIR" "backend"
install_if_needed "$FRONTEND_DIR" "frontend"
# ── Launch both processes ────────────────────
cleanup() {
log "Shutting down..."
kill $BACKEND_PID $FRONTEND_PID 2>/dev/null || true
wait $BACKEND_PID $FRONTEND_PID 2>/dev/null || true
log "Done."
}
trap cleanup EXIT INT TERM
log "Starting backend (http://localhost:3000)..."
(cd "$BACKEND_DIR" && npm run dev) &
BACKEND_PID=$!
# Give backend a moment to start before launching frontend
sleep 2
log "Starting frontend (http://localhost:5173)..."
(cd "$FRONTEND_DIR" && npm run dev) &
FRONTEND_PID=$!
echo ""
echo -e "${GREEN}════════════════════════════════════════════════${NC}"
echo -e "${GREEN} Calendar Assistant — Local Development${NC}"
echo -e "${GREEN}────────────────────────────────────────────────${NC}"
echo -e " Frontend: ${CYAN}http://localhost:5173${NC}"
echo -e " Backend: ${CYAN}http://localhost:3000${NC}"
echo -e " Health: ${CYAN}http://localhost:3000/health${NC}"
echo -e "${GREEN}════════════════════════════════════════════════${NC}"
echo -e " Press ${RED}Ctrl+C${NC} to stop both servers."
echo ""
wait