WMS_MAIN/script/tmp-update-ai-method-routing.cjs
2026-03-23 17:10:07 +08:00

31 lines
1.5 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const fs = require('fs');
const path = require('path');
const root = process.cwd();
const target = path.join(root, 'AI_METHOD_ROUTING.md');
const inventoryPath = path.join(root, 'temp', 'tmp-service-method-inventory.md');
const base = fs.readFileSync(target, 'utf8');
const inventory = fs.readFileSync(inventoryPath, 'utf8').trim();
const section = `\n\n## 6. 全量 Service Method 能力清单(自动扫描)\n\n维护说明:\n- 扫描范围:app/service/**/*.js\n- 本节内容由脚本生成,新增/修改 service 后请同步刷新。\n- 刷新命令:node .\\script\\tmp-gen-service-method-inventory.cjs\n- 临时清单输出:temp/tmp-service-method-inventory.md\n\n<!-- SERVICE_METHOD_INVENTORY:BEGIN -->\n${inventory}\n<!-- SERVICE_METHOD_INVENTORY:END -->\n`;
const begin = '<!-- SERVICE_METHOD_INVENTORY:BEGIN -->';
const end = '<!-- SERVICE_METHOD_INVENTORY:END -->';
let next;
if (base.includes(begin) && base.includes(end)) {
const start = base.indexOf(begin);
const finish = base.indexOf(end) + end.length;
const head = base.slice(0, base.lastIndexOf('\n## 6. 全量 Service Method 能力清单(自动扫描)', start) >= 0
? base.lastIndexOf('\n## 6. 全量 Service Method 能力清单(自动扫描)', start)
: start);
const tail = base.slice(finish);
next = head.trimEnd() + section + tail;
} else {
next = base.trimEnd() + section;
}
fs.writeFileSync(target, next + '\n', 'utf8');
console.log('UPDATED AI_METHOD_ROUTING.md');