添加run.bat

This commit is contained in:
2026-08-21 14:12:27 +08:00
parent a44f703619
commit 9d331cc37f
4 changed files with 130 additions and 4 deletions
+30 -1
View File
@@ -7,6 +7,8 @@ BACKEND_PORT="${BACKEND_PORT:-8000}"
FRONTEND_HOST="${FRONTEND_HOST:-127.0.0.1}"
FRONTEND_PORT="${FRONTEND_PORT:-5173}"
PYTHON_BIN="${PYTHON_BIN:-python3}"
BACKEND_VENV="${ROOT_DIR}/backend/.venv"
BACKEND_PYTHON="${BACKEND_VENV}/bin/python"
cleanup() {
local pids
@@ -28,6 +30,11 @@ if [[ ! -f "${ROOT_DIR}/frontend/package.json" ]]; then
exit 1
fi
if [[ ! -f "${ROOT_DIR}/backend/requirements.txt" ]]; then
echo "Backend requirements not found: backend/requirements.txt"
exit 1
fi
command -v "${PYTHON_BIN}" >/dev/null 2>&1 || {
echo "Python executable not found: ${PYTHON_BIN}"
exit 1
@@ -38,10 +45,32 @@ command -v npm >/dev/null 2>&1 || {
exit 1
}
if [[ ! -x "${BACKEND_PYTHON}" ]]; then
echo "Creating backend virtual environment..."
"${PYTHON_BIN}" -m venv "${BACKEND_VENV}"
fi
if ! "${BACKEND_PYTHON}" -c 'import build123d, dotenv, fastapi, httpx, jsonschema, multipart, uvicorn' >/dev/null 2>&1; then
echo "Installing backend dependencies..."
"${BACKEND_PYTHON}" -m pip install -r "${ROOT_DIR}/backend/requirements.txt"
fi
if [[ ! -d "${ROOT_DIR}/frontend/node_modules/next" ]]; then
echo "Installing frontend dependencies..."
(
cd "${ROOT_DIR}/frontend"
if [[ -f package-lock.json ]]; then
npm ci
else
npm install
fi
)
fi
echo "Starting backend on ${BACKEND_HOST}:${BACKEND_PORT}"
(
cd "${ROOT_DIR}/backend"
"${PYTHON_BIN}" -m uvicorn app.main:app \
"${BACKEND_PYTHON}" -m uvicorn app.main:app \
--host "${BACKEND_HOST}" \
--port "${BACKEND_PORT}" \
--reload