-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun-dev.sh
More file actions
executable file
·94 lines (86 loc) · 2.98 KB
/
Copy pathrun-dev.sh
File metadata and controls
executable file
·94 lines (86 loc) · 2.98 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
#!/usr/bin/env bash
#
# One command to run the GUI for DEVELOPMENT.
#
# DEFAULT is LIVE: the GUI talks to the real FastAPI service, and NO mock data is
# served or renderable in this mode. Both the rotating-mode (MODESPEC) and the
# quasi-stationary (SLCONTOUR) analyses serve real results from fetched shots. Use
# `static` only for offline frontend work against the demo fixtures.
#
# ./run-dev.sh live — FastAPI service (:8000) + GUI (:5173) against it (default)
# ./run-dev.sh static demo — GUI on :5173 only, STATIC mock fixtures (no backend)
# ./run-dev.sh --prod deploy — build the GUI and serve it on one port (:8000)
#
# To build a distributable wheel/sdist (not just preview it), use scripts/build-dist.sh.
#
# Press Ctrl-C to stop. Prereqs: Node.js 22 + uv (uv only needed for live/--prod).
set -euo pipefail
cd "$(dirname "$0")"
MODE="${1:-live}"
echo "▶ ensuring GUI deps (npm)…"
[ -d gui/web/node_modules ] || ( cd gui/web && npm install )
case "$MODE" in
static|--static|dev)
echo ""
echo " ✓ open http://localhost:5173 (GUI, hot-reload; STATIC mock fixtures — demo only)"
echo ""
cd gui/web
exec npm run dev
;;
--live|live|"")
echo "▶ syncing Python deps (uv)…"
uv sync --quiet
# Auto-pick a free backend port (prefer 8000) so several checkouts can run at
# once without colliding. Vite already auto-picks a free GUI port; we just wire
# the GUI to whichever backend port we grabbed. Override with `PORT=NNNN ./run-dev.sh`.
PORT="${PORT:-$(python3 - <<'PY'
import socket
def free(p):
s = socket.socket()
try:
s.bind(("127.0.0.1", p))
return True
except OSError:
return False
finally:
s.close()
for p in range(8000, 8100):
if free(p):
print(p)
break
else: # everything 8000-8099 busy — let the OS pick any free port
s = socket.socket()
s.bind(("127.0.0.1", 0))
print(s.getsockname()[1])
s.close()
PY
)}"
echo "▶ starting service (:$PORT) + GUI dev server (Vite auto-port)…"
PORT="$PORT" uv run magnetics-service &
SERVICE_PID=$!
( cd gui/web && VITE_API_BASE="http://127.0.0.1:$PORT" npm run dev ) &
GUI_PID=$!
trap 'echo; echo "▶ stopping…"; kill "$SERVICE_PID" "$GUI_PID" 2>/dev/null || true' EXIT INT TERM
echo ""
echo " ✓ open the GUI URL Vite prints below (LIVE against :$PORT — no mock data)"
echo ""
wait
;;
--prod|prod)
echo "▶ syncing Python deps (uv)…"
uv sync --quiet
echo "▶ building GUI…"
( cd gui/web && npm run build )
echo "▶ staging built GUI into the package (magnetics/service/webapp)…"
rm -rf src/magnetics/service/webapp
cp -r gui/web/dist src/magnetics/service/webapp
echo ""
echo " ✓ open http://127.0.0.1:8000 (single origin — GUI served on one port)"
echo ""
exec uv run magnetics-service
;;
*)
echo "usage: ./run-dev.sh [live | static | --prod]" >&2
exit 2
;;
esac