feat: 新增 scripts 一键脚本与 YAML 配置生成 env
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
# /// script
|
||||
# requires-python = ">=3.9"
|
||||
# dependencies = ["pyyaml"]
|
||||
# ///
|
||||
"""本地开发一键启动:生成 .env -> 起 MySQL/Redis -> 构建 shared -> 迁移+种子 -> 同时启动 api/admin/h5。
|
||||
|
||||
用法:
|
||||
uv run scripts/dev.py # 完整启动
|
||||
uv run scripts/dev.py --no-seed # 跳过种子数据
|
||||
uv run scripts/dev.py --install # 先 pnpm install
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import sys
|
||||
import time
|
||||
|
||||
from _lib import ROOT, build_env, load_config, popen, run, wait_port, write_env
|
||||
|
||||
|
||||
def main() -> None:
|
||||
args = sys.argv[1:]
|
||||
cfg = load_config()
|
||||
env = build_env(cfg)
|
||||
write_env(env)
|
||||
|
||||
if "--install" in args:
|
||||
run("pnpm install")
|
||||
|
||||
# 1. 启动数据库与缓存
|
||||
run("docker compose --env-file .env -f docker/docker-compose.dev.yml up -d")
|
||||
wait_port(cfg["database"]["host"], int(cfg["database"]["port"]), 90)
|
||||
wait_port(cfg["redis"]["host"], int(cfg["redis"]["port"]), 30)
|
||||
time.sleep(3) # 给 MySQL 初始化留余量
|
||||
|
||||
# 2. 构建共享包
|
||||
run("pnpm build:shared")
|
||||
|
||||
# 3. 数据库迁移 + 种子
|
||||
run("pnpm --filter @artveris/api prisma:generate")
|
||||
run("pnpm --filter @artveris/api prisma:deploy")
|
||||
if "--no-seed" not in args:
|
||||
run("pnpm --filter @artveris/api seed", check=False)
|
||||
|
||||
# 4. 同时启动三端
|
||||
procs = [
|
||||
popen("pnpm dev:api"),
|
||||
popen("pnpm dev:admin"),
|
||||
popen("pnpm dev:h5"),
|
||||
]
|
||||
app = cfg["app"]
|
||||
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['h5_port']}")
|
||||
print(" 按 Ctrl+C 退出全部。\n")
|
||||
try:
|
||||
for p in procs:
|
||||
p.wait()
|
||||
except KeyboardInterrupt:
|
||||
print("\n[artveris] 正在停止 …")
|
||||
for p in procs:
|
||||
p.terminate()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user