feat: 增加本地安装页调试模式

This commit is contained in:
Nixevol
2026-07-07 03:00:59 +08:00
parent beb458d28d
commit eec4aaebf4
9 changed files with 57 additions and 10 deletions
+42 -9
View File
@@ -10,17 +10,21 @@
python scripts/dev.py --install # 先 pnpm install
python scripts/dev.py --auto # 跳过询问,直接用 Docker 编排起 MySQL/Redis
python scripts/dev.py --manual # 跳过询问,连接已有的 MySQL/Redis(用记忆/配置中的连接信息)
python scripts/dev.py --install-mode # 本地调试首次安装页(API + install,不跑迁移/种子)
python scripts/dev.py --yes # 手动模式下不逐项询问,直接采用默认值
"""
from __future__ import annotations
import sys
import shutil
import threading
import time
from pathlib import Path
COMPOSE_DEV_CMD = "docker compose --env-file .env -f docker/docker-compose.dev.yml up -d"
MYSQL_1PANEL_IMAGE = "docker.1panel.live/library/mysql:8.0"
REDIS_1PANEL_IMAGE = "docker.1panel.live/library/redis:7-alpine"
INSTALL_DEV_RUNTIME_DIR = Path(__file__).resolve().parent.parent / "apps/api/runtime/install-dev"
from _lib import (
ask,
@@ -142,19 +146,38 @@ def resolve_datasource(cfg: dict, args: list[str]) -> str:
def main() -> None:
args = sys.argv[1:]
install_mode = "--install-mode" in args
cfg = load_config()
app = cfg["app"]
# 选择数据源(可能覆盖 cfg.database / cfg.redis),再据此生成 .env
mode = resolve_datasource(cfg, args)
env = build_env(cfg)
if install_mode:
env["ARTVERIS_INSTALL_MODE"] = "1"
env["ARTVERIS_RUNTIME_DIR"] = str(INSTALL_DEV_RUNTIME_DIR).replace("\\", "/")
env["INSTALL_PREFILL_SECRETS"] = "1"
env["INSTALL_MYSQL_HOST"] = db_host = str(cfg["database"]["host"])
env["INSTALL_MYSQL_PORT"] = str(cfg["database"]["port"])
env["INSTALL_MYSQL_PASSWORD"] = str(cfg["database"].get("password", ""))
env["INSTALL_REDIS_HOST"] = str(cfg["redis"]["host"])
env["INSTALL_REDIS_PORT"] = str(cfg["redis"]["port"])
env["INSTALL_REDIS_PASSWORD"] = str(cfg["redis"].get("password", ""))
if db_host in {"localhost", "127.0.0.1"}:
env["INSTALL_MYSQL_HOST"] = "127.0.0.1"
if str(cfg["redis"]["host"]) in {"localhost", "127.0.0.1"}:
env["INSTALL_REDIS_HOST"] = "127.0.0.1"
write_env(env)
# 0. 彻底清理上次残留服务(按命令行清掉 idle 的 nest --watch 监视器,避免其重启抢占端口;
# 同时解除对 Prisma 引擎 DLL 的占用,避免 generate EPERM)
ports = [app["api_port"], app["admin_port"], app["client_port"]]
if install_mode:
ports.append(5175)
kill_project_servers(ports=ports)
time.sleep(1.5)
if install_mode and INSTALL_DEV_RUNTIME_DIR.exists():
shutil.rmtree(INSTALL_DEV_RUNTIME_DIR)
ensure_pnpm()
if "--install" in args:
@@ -208,9 +231,12 @@ def main() -> None:
# 3. 数据库迁移 + 种子(generate 偶发被占用,自动重试)
if not run_retry("pnpm --filter @artveris/api prisma:generate", attempts=4, delay=2):
print("[artveris] 警告:prisma generate 仍失败(客户端可能已存在),继续启动 …")
run("pnpm --filter @artveris/api prisma:deploy")
if "--no-seed" not in args:
run("pnpm --filter @artveris/api seed", check=False)
if install_mode:
print("[artveris] install-mode:跳过 prisma migrate/seed,保留安装页首次初始化流程。")
else:
run("pnpm --filter @artveris/api prisma:deploy")
if "--no-seed" not in args:
run("pnpm --filter @artveris/api seed", check=False)
# 4. 同时启动三端
# 加入 KILL_ON_JOB_CLOSE 的 Job:本脚本无论如何退出,子进程都会被系统连带结束
@@ -241,12 +267,19 @@ def main() -> None:
print("[artveris] 后端 API 已就绪")
else:
print("[artveris] 后端 API 等待超时,仍继续启动前端(稍后会自动恢复)")
procs.append(popen("pnpm dev:admin", job=job))
procs.append(popen("pnpm dev:client", job=job))
print("\n[artveris] 开发服务启动中:")
print(f" 后端 API : http://localhost:{app['api_port']}/api (文档 /api/docs)")
print(f" 管理后台 : http://localhost:{app['admin_port']}")
print(f" C 端 : http://localhost:{app['client_port']}")
if install_mode:
procs.append(popen("pnpm dev:install", job=job))
print("\n[artveris] 安装页调试服务启动中:")
print(f" 安装页 : http://localhost:5175")
print(f" 安装 API : http://localhost:{app['api_port']}/api/install/status")
print(" 说明 : 安装成功后 API 会退出;重新运行普通 `python scripts/dev.py --auto` 可进入正式开发模式。")
else:
procs.append(popen("pnpm dev:admin", job=job))
procs.append(popen("pnpm dev:client", job=job))
print("\n[artveris] 开发服务启动中:")
print(f" 后端 API : http://localhost:{app['api_port']}/api (文档 /api/docs)")
print(f" 管理后台 : http://localhost:{app['admin_port']}")
print(f" C 端 : http://localhost:{app['client_port']}")
print(" 按 Ctrl+C 退出全部。\n")
for p in procs:
p.wait()