Repository navigation
Expand file tree
/
Copy pathdev
More file actions
executable file
·113 lines (104 loc) · 3.78 KB
/
Copy pathdev
File metadata and controls
executable file
·113 lines (104 loc) · 3.78 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
#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
PIDFILE="/tmp/memorygrain-web-dev.pid"
LOGFILE="/tmp/memorygrain-web-dev.log"
PORT=4022
NAME="MemoryGrain website"
CLOUD_COMPOSE="$SCRIPT_DIR/scripts/dev/docker-compose.cloud.yml"
# ─── Cloud container mode (build + run the production image in Docker) ────────
cloud_cmd() {
local sub="${1:-up}"; shift 2>/dev/null || true
if [ ! -f "$CLOUD_COMPOSE" ]; then
echo "error: $CLOUD_COMPOSE not found" >&2; exit 1
fi
case "$sub" in
up|start|"")
echo "Building and starting $NAME cloud container…"
echo "(First build compiles the production image — this can take a while)"
docker compose -f "$CLOUD_COMPOSE" up --build -d
echo ""
echo "$NAME cloud container:"
echo " Site: http://localhost:${PORT}"
echo " Logs: ./dev cloud logs"
echo " Stop: ./dev cloud down"
echo " Reset: ./dev cloud clean"
;;
down|stop) docker compose -f "$CLOUD_COMPOSE" down ;;
clean) docker compose -f "$CLOUD_COMPOSE" down -v --rmi local ;;
status|ps) docker compose -f "$CLOUD_COMPOSE" ps ;;
logs) docker compose -f "$CLOUD_COMPOSE" logs -f "$@" ;;
restart) docker compose -f "$CLOUD_COMPOSE" restart "$@" ;;
*) echo "Usage: ./dev cloud [up|down|clean|status|logs|restart]" >&2; exit 1 ;;
esac
}
# ─── Commands: cloud, stop, restart, status ──────────────────────────────────
CMD="${1:-start}"
case "$CMD" in
cloud)
shift
cloud_cmd "$@"
exit 0
;;
stop)
if [ -f "$PIDFILE" ]; then
PID=$(cat "$PIDFILE")
if kill -0 "$PID" 2>/dev/null; then
kill "$PID" 2>/dev/null
wait "$PID" 2>/dev/null || true
echo "Stopped (PID $PID)"
else
echo "PID $PID not running"
fi
rm -f "$PIDFILE"
else
lsof -ti :${PORT} 2>/dev/null | xargs kill 2>/dev/null || true
echo "Stopped (by port)"
fi
exit 0
;;
restart)
"$0" stop
sleep 1
shift
exec "$0" start "$@"
;;
status)
if [ -f "$PIDFILE" ] && kill -0 "$(cat "$PIDFILE")" 2>/dev/null; then
echo "Running (PID $(cat "$PIDFILE"))"
echo " Site: http://localhost:${PORT}"
echo " Log: $LOGFILE"
else
echo "Not running"
fi
exit 0
;;
start) shift || true ;;
*) ;; # treat unknown args as passthrough
esac
# ─── Kill anything already on our port ───────────────────────────────────────
lsof -ti :${PORT} 2>/dev/null | xargs kill 2>/dev/null || true
# ─── Cleanup ─────────────────────────────────────────────────────────────────
cleanup() {
echo ""
echo "Shutting down…"
kill $DEV_PID 2>/dev/null || true
wait $DEV_PID 2>/dev/null || true
rm -f "$PIDFILE"
}
DEV_PID=0
trap cleanup EXIT
# ─── Write PID file ──────────────────────────────────────────────────────────
echo $$ > "$PIDFILE"
# ─── Start Next.js dev server ────────────────────────────────────────────────
# Uses `npm run dev` so the `predev` hook (fetches OMS/CAL/SML specs) runs and
# the canonical `--turbopack -p ${PORT}` flags from package.json are preserved.
cd "$SCRIPT_DIR"
npm run dev -- "$@" &
DEV_PID=$!
echo ""
echo "MemoryGrain website dev server:"
echo " Site: http://localhost:${PORT}"
echo " Log: $LOGFILE"
echo ""
wait