nex_buddy/scripts/dev.sh

24 lines
766 B
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#!/usr/bin/env bash
# 开发期启动:scripts/dev.sh [端口]
# 后端端口默认取 .env 的 BACKEND_PORT(没有就用 8000);命令行参数优先级更高。
set -euo pipefail
cd "$(dirname "$0")/.."
PORT="${1:-}"
if [ -z "$PORT" ]; then
PORT="$(grep -E '^BACKEND_PORT=' .env 2>/dev/null | tail -1 | cut -d= -f2 | tr -d '[:space:]' || true)"
PORT="${PORT:-8000}"
fi
if [ ! -d .venv ]; then
echo ">> 创建虚拟环境"
python3 -m venv .venv
.venv/bin/python -m pip -q install -r requirements.txt
fi
echo ">> 迁移数据库"
(cd server && ../.venv/bin/python -m alembic upgrade head)
echo ">> 启动 http://0.0.0.0:${PORT} (文档 /docs)"
cd server && exec ../.venv/bin/python -m uvicorn app.main:app --host 0.0.0.0 --port "$PORT" --reload