forked from Donkie/Spoolman
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdev.sh
More file actions
116 lines (97 loc) · 4.73 KB
/
Copy pathdev.sh
File metadata and controls
116 lines (97 loc) · 4.73 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
115
116
#!/bin/bash
set -e
# ── colours ───────────────────────────────────────────────────────────────────
GREEN='\033[0;32m'
ORANGE='\033[0;33m'
CYAN='\033[0;36m'
RED='\033[0;31m'
NC='\033[0m'
info() { echo -e "${GREEN}[dev]${NC} $*"; }
warn() { echo -e "${ORANGE}[dev]${NC} $*"; }
error() { echo -e "${RED}[dev]${NC} $*"; }
# ── cd to repo root ────────────────────────────────────────────────────────────
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
# ── 1. uv ──────────────────────────────────────────────────────────────────────
if ! command -v uv &>/dev/null; then
warn "uv not found — installing..."
curl -LsSf https://astral.sh/uv/install.sh | sh
# add to PATH for this session
export PATH="$HOME/.local/bin:$PATH"
fi
# ── 2. Python venv + deps ──────────────────────────────────────────────────────
if [ ! -d ".venv" ]; then
info "Creating .venv and installing Python dependencies..."
uv sync --no-dev
else
info "Python venv already exists — syncing dependencies..."
uv sync --no-dev --quiet
fi
# ── 3. Backend .env ────────────────────────────────────────────────────────────
if [ ! -f ".env" ]; then
info "Creating .env from .env.example..."
cp .env.example .env
fi
# Ensure debug mode is on (allows CORS from the Vite dev server)
if ! grep -qE "^SPOOLMAN_DEBUG_MODE=TRUE" .env; then
# Remove any existing (commented or set to FALSE) debug line and append the right value
sed -i '/SPOOLMAN_DEBUG_MODE/d' .env
echo "SPOOLMAN_DEBUG_MODE=TRUE" >> .env
info "Enabled SPOOLMAN_DEBUG_MODE in .env"
fi
# ── 4. Frontend deps ───────────────────────────────────────────────────────────
if [ ! -d "client/node_modules" ]; then
info "Installing frontend dependencies..."
npm install --prefix client
else
info "Frontend node_modules already present — skipping npm install"
fi
# ── 5. Frontend .env.local ────────────────────────────────────────────────────
if [ ! -f "client/.env.local" ]; then
info "Creating client/.env.local..."
echo "VITE_APIURL=/api/v1" > client/.env.local
fi
# ── 6. Ensure client/dist exists (backend mounts it as static files on startup) ──
if [ ! -d "client/dist" ]; then
info "Creating client/dist placeholder so the backend can start..."
mkdir -p client/dist
echo "<!-- dev placeholder -->" > client/dist/index.html
fi
# ── 7. Start both servers ──────────────────────────────────────────────────────
info "Starting backend → http://localhost:7912"
info "Starting frontend → http://localhost:5173"
info "Press Ctrl+C to stop both."
echo ""
# Log files so output from both processes is readable
BACKEND_LOG="/tmp/spoolman-backend.log"
FRONTEND_LOG="/tmp/spoolman-frontend.log"
source .venv/bin/activate
# Start backend
uvicorn spoolman.main:app --host 0.0.0.0 --port 7912 --reload \
2>&1 | tee "$BACKEND_LOG" &
BACKEND_PID=$!
# Give the backend a moment to bind the port before the frontend starts
sleep 1
# Start frontend
npm run dev --prefix client \
2>&1 | tee "$FRONTEND_LOG" &
FRONTEND_PID=$!
# ── cleanup on Ctrl+C ─────────────────────────────────────────────────────────
cleanup() {
echo ""
info "Shutting down..."
kill "$BACKEND_PID" 2>/dev/null || true
kill "$FRONTEND_PID" 2>/dev/null || true
wait "$BACKEND_PID" 2>/dev/null || true
wait "$FRONTEND_PID" 2>/dev/null || true
info "Done. Logs saved to $BACKEND_LOG and $FRONTEND_LOG"
}
trap cleanup INT TERM
# Wait for either process to exit unexpectedly
wait -n 2>/dev/null || {
# wait -n not available on older bash — fall back to polling
while kill -0 "$BACKEND_PID" 2>/dev/null && kill -0 "$FRONTEND_PID" 2>/dev/null; do
sleep 1
done
}
cleanup