import { mkdir, writeFile } from "node:fs/promises"; import path from "node:path"; import { API_DOC_SYSTEM_CONFIG } from "./config.mjs"; function formatLocalDateTime(input = new Date()) { const date = input instanceof Date ? input : new Date(input); const year = String(date.getFullYear()); const month = String(date.getMonth() + 1).padStart(2, "0"); const day = String(date.getDate()).padStart(2, "0"); const hours = String(date.getHours()).padStart(2, "0"); const minutes = String(date.getMinutes()).padStart(2, "0"); const seconds = String(date.getSeconds()).padStart(2, "0"); return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`; } async function clearPendingUpdates() { const now = new Date(); const pendingFilePath = API_DOC_SYSTEM_CONFIG.file.pendingUpdates; const payload = { generatedAt: now.toISOString(), generatedAtLocal: formatLocalDateTime(now), summary: { moduleAdded: 0, moduleDeleted: 0, moduleUpdated: 0, moduleSplit: 0, moduleMerged: 0, moduleReplaced: 0, interfaceAdded: 0, interfaceDeleted: 0, interfaceParamsUpdated: 0, interfaceResponseUpdated: 0, movedAcrossModules: 0, totalChangedItems: 0, }, moduleUpdates: { added: [], deleted: [], updated: [], split: [], merged: [], replaced: [], }, interfaceUpdates: { added: [], deleted: [], paramsUpdated: [], responseUpdated: [], }, legacy: [], versionWindow: { keepLatest: API_DOC_SYSTEM_CONFIG.retentionDays, recentVersions: [], }, }; await mkdir(path.dirname(pendingFilePath), { recursive: true }); await writeFile(pendingFilePath, `${JSON.stringify(payload, null, 2)}\n`, "utf8"); console.log(`执行时间: ${payload.generatedAtLocal}`); console.log(`已清空待更新接口文件: ${pendingFilePath}`); } clearPendingUpdates().catch((error) => { console.error("清空待更新接口失败:", error.message); process.exitCode = 1; });