UNPKG

@vectorx/cloud-toolkit

Version:

VectorX Cloud Toolkit

55 lines (54 loc) 2.58 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.mergeProjectConfigs = mergeProjectConfigs; const fs_1 = __importDefault(require("fs")); const path_1 = __importDefault(require("path")); function mergeProjectConfigs(workDir) { const projectConfigPath = path_1.default.join(workDir, "project.config.json"); const agentConfigPath = path_1.default.join(workDir, "agent-cloudbase-functions.json"); if (!fs_1.default.existsSync(projectConfigPath)) { throw new Error(`project.config.json 文件不存在: ${projectConfigPath}`); } if (!fs_1.default.existsSync(agentConfigPath)) { throw new Error(`agent-cloudbase-functions.json 文件不存在: ${agentConfigPath}`); } try { const projectConfigContent = fs_1.default.readFileSync(projectConfigPath, "utf8"); const agentConfigContent = fs_1.default.readFileSync(agentConfigPath, "utf8"); const projectConfig = JSON.parse(projectConfigContent); const agentConfig = JSON.parse(agentConfigContent); let hasChanges = false; if (projectConfig.agentId && projectConfig.agentId !== agentConfig.agentId) { agentConfig.agentId = projectConfig.agentId; hasChanges = true; } if (projectConfig.version && projectConfig.version !== agentConfig.version) { agentConfig.version = projectConfig.version; hasChanges = true; } if (projectConfig.desc && projectConfig.desc !== agentConfig.desc) { agentConfig.desc = projectConfig.desc; hasChanges = true; } if (hasChanges) { const updatedContent = JSON.stringify(agentConfig, null, 2); fs_1.default.writeFileSync(agentConfigPath, updatedContent, "utf8"); console.log("✅ 配置文件合并完成,已更新 agent-cloudbase-functions.json"); if (projectConfig.agentId) { console.log(` agentId: ${projectConfig.agentId}`); } if (projectConfig.version) { console.log(` version: ${projectConfig.version}`); } } } catch (error) { if (error instanceof SyntaxError) { throw new Error(`配置文件格式错误,请检查 JSON 格式是否正确: ${error.message}`); } throw new Error(`合并配置文件时发生错误: ${error.message}`); } }