Executable
+78
@@ -0,0 +1,78 @@
|
||||
#!/usr/bin/env bash
|
||||
# 在仓库任意目录记这三条就够:
|
||||
# npm run be 只开后端 http://127.0.0.1:8010
|
||||
# npm run fe 只开前端 http://127.0.0.1:5173
|
||||
# npm run dev 两个一起开(在项目根目录)
|
||||
set -euo pipefail
|
||||
|
||||
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
|
||||
MODE="${1:-all}"
|
||||
PY="$ROOT/core/backend/.venv/bin/python"
|
||||
|
||||
listening() {
|
||||
lsof -nP -iTCP:"$1" -sTCP:LISTEN >/dev/null 2>&1
|
||||
}
|
||||
|
||||
need_python() {
|
||||
if [[ -x "$PY" ]]; then
|
||||
return 0
|
||||
fi
|
||||
echo "后端环境还没装好。在项目里执行一次:"
|
||||
echo " cd core/backend && python3.12 -m venv .venv && .venv/bin/pip install -r requirements.txt"
|
||||
exit 1
|
||||
}
|
||||
|
||||
start_backend() {
|
||||
need_python
|
||||
if listening 8010; then
|
||||
echo "后端已经在跑: http://127.0.0.1:8010"
|
||||
return 0
|
||||
fi
|
||||
echo "后端 → http://127.0.0.1:8010"
|
||||
cd "$ROOT/core/backend"
|
||||
exec "$PY" manage.py runserver 0.0.0.0:8010
|
||||
}
|
||||
|
||||
start_frontend() {
|
||||
if listening 5173; then
|
||||
echo "前端已经在跑: http://127.0.0.1:5173"
|
||||
return 0
|
||||
fi
|
||||
if [[ ! -d "$ROOT/core/frontend/node_modules" ]]; then
|
||||
echo "第一次开前端,先装依赖…"
|
||||
npm --prefix "$ROOT/core/frontend" install
|
||||
fi
|
||||
echo "前端 → http://127.0.0.1:5173"
|
||||
cd "$ROOT/core/frontend"
|
||||
exec npm run dev
|
||||
}
|
||||
|
||||
case "$MODE" in
|
||||
be|backend)
|
||||
start_backend
|
||||
;;
|
||||
fe|frontend)
|
||||
start_frontend
|
||||
;;
|
||||
all|dev)
|
||||
need_python
|
||||
trap 'kill 0' INT TERM
|
||||
if listening 8010; then
|
||||
echo "后端已经在跑: http://127.0.0.1:8010"
|
||||
else
|
||||
echo "后端 → http://127.0.0.1:8010"
|
||||
(cd "$ROOT/core/backend" && "$PY" manage.py runserver 0.0.0.0:8010) &
|
||||
fi
|
||||
if listening 5173; then
|
||||
echo "前端已经在跑: http://127.0.0.1:5173"
|
||||
else
|
||||
echo "前端 → http://127.0.0.1:5173"
|
||||
(cd "$ROOT/core/frontend" && npm run dev) &
|
||||
fi
|
||||
wait
|
||||
;;
|
||||
*)
|
||||
echo "用法: npm run be | npm run fe | npm run dev"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
Reference in New Issue
Block a user