import { existsSync } from "node:fs"; import path from "node:path"; import { fileURLToPath } from "node:url"; /** * 启动前依赖自检。 * 目的:依赖缺失时给出明确指引,而不是让 `go run` / `vite` 抛出难以定位的报错。 */ const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), ".."); const CHECKS = [ { label: "根目录开发工具 concurrently", target: "node_modules/concurrently" }, { label: "前端依赖", target: "web/node_modules" }, { label: "后端依赖", target: "backend/go.sum" }, ]; const missing = CHECKS.filter((item) => !existsSync(path.join(root, item.target))); if (missing.length > 0) { console.error("\n依赖未就绪,已中止启动。\n"); for (const item of missing) { console.error(` x ${item.label} (未找到 ${item.target})`); } console.error("\n请在项目根目录依次执行:\n"); console.error(" pnpm install # 安装 concurrently"); console.error(" pnpm setup # 安装 web / backend / desktop 依赖\n"); process.exit(1); }