-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdev.sh
More file actions
83 lines (73 loc) · 2.31 KB
/
dev.sh
File metadata and controls
83 lines (73 loc) · 2.31 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
#!/usr/bin/env bash
set -euo pipefail
source "$(dirname "${BASH_SOURCE[0]}")/lib/common.sh"
if ! command -v git >/dev/null 2>&1; then
echo "scripts/dev.sh: git is required but not installed" >&2
exit 1
fi
if [[ -d "/opt/homebrew/opt/node@20/bin" ]]; then
export PATH="/opt/homebrew/opt/node@20/bin:$PATH"
fi
ROOT_DIR="$(git rev-parse --show-toplevel 2>/dev/null)"
if [[ -z "${ROOT_DIR}" || ! -d "${ROOT_DIR}" ]]; then
echo "scripts/dev.sh: unable to locate repository root" >&2
exit 1
fi
cd "${ROOT_DIR}"
ensure_dir frontend
ensure_dir backend
case "${1:-}" in
fe)
ensure_cmd npx
ensure_cmd node
mkdir -p logs
cd frontend
PORT="${PORT:-3001}"
kill_port "${PORT}"
nohup npx next dev -p "${PORT}" > "../logs/dev_${PORT}.log" 2>&1 &
echo "$!" > .next.pid
FRONTEND_PID="$(cat .next.pid)"
echo "Next dev on :${PORT} (PID ${FRONTEND_PID})"
;;
be)
ensure_cmd uvicorn
mkdir -p logs
PORT="${BACKEND_PORT:-8000}"
kill_port "${PORT}"
if [[ -z "${ODOO_ADMIN_USER:-}" || -z "${ODOO_ADMIN_PASS:-}" ]]; then
echo "scripts/dev.sh: set ODOO_ADMIN_USER and ODOO_ADMIN_PASS before starting the backend" >&2
exit 1
fi
export ODOO_BASE_URL="${ODOO_BASE_URL:-http://localhost:8069}"
export ODOO_DB="${ODOO_DB:-paform}"
export ODOO_USERNAME="${ODOO_ADMIN_USER}"
export ODOO_API_KEY="${ODOO_ADMIN_PASS}"
LOG_PATH="logs/dev_${PORT}.log"
nohup uvicorn backend.main:app --port "${PORT}" --log-level info > "${LOG_PATH}" 2>&1 &
echo "$!" > .uv.pid
BACKEND_PID="$(cat .uv.pid)"
echo "Backend on :${PORT} (PID ${BACKEND_PID})"
;;
stop)
FRONTEND_PORT="${PORT:-3001}"
if [[ -f frontend/.next.pid ]]; then
FRONTEND_PID="$(cat frontend/.next.pid)"
if ! kill "${FRONTEND_PID}" 2>/dev/null; then
echo "scripts/dev.sh: failed to stop frontend process ${FRONTEND_PID} on :${FRONTEND_PORT}" >&2
fi
rm -f frontend/.next.pid
fi
BACKEND_PORT_VALUE="${BACKEND_PORT:-8000}"
if [[ -f .uv.pid ]]; then
BACKEND_PID="$(cat .uv.pid)"
if ! kill "${BACKEND_PID}" 2>/dev/null; then
echo "scripts/dev.sh: failed to stop backend process ${BACKEND_PID} on :${BACKEND_PORT_VALUE}" >&2
fi
rm -f .uv.pid
fi
;;
*)
echo "usage: scripts/dev.sh {fe|be|stop}" >&2
exit 2
;;
esac