iter(f05): index 幂等化防时间戳弄脏工作区
This commit is contained in:
@@ -56,6 +56,13 @@ function collectManifests() {
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*** 内容无变化则跳过写入(幂等,行尾归一化防 CRLF 误判),避免时间戳刷新弄脏工作区 ***/
|
||||||
|
function writeIfChanged(file, content) {
|
||||||
|
if (fs.existsSync(file) && fs.readFileSync(file, 'utf8').replace(/\r\n/g, '\n') === content) return false;
|
||||||
|
fs.writeFileSync(file, content);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/*** 聚合清单,生成 .ua/index.json 与 llms.txt ***/
|
/*** 聚合清单,生成 .ua/index.json 与 llms.txt ***/
|
||||||
function cmdIndex() {
|
function cmdIndex() {
|
||||||
const packages = collectManifests();
|
const packages = collectManifests();
|
||||||
@@ -66,7 +73,11 @@ function cmdIndex() {
|
|||||||
repoRoot: '.',
|
repoRoot: '.',
|
||||||
packages,
|
packages,
|
||||||
};
|
};
|
||||||
fs.writeFileSync(INDEX_FILE, JSON.stringify(index, null, 2) + '\n');
|
// 幂等:剔除 generatedAt 后内容一致即不写入,连续 check 不弄脏工作区
|
||||||
|
const json = JSON.stringify(index, null, 2) + '\n';
|
||||||
|
const stripTs = (s) => s.replace(/"generatedAt": "[^"]*"/, '"generatedAt": ""');
|
||||||
|
const changed = !fs.existsSync(INDEX_FILE) || stripTs(fs.readFileSync(INDEX_FILE, 'utf8').replace(/\r\n/g, '\n')) !== stripTs(json);
|
||||||
|
if (changed) fs.writeFileSync(INDEX_FILE, json);
|
||||||
|
|
||||||
const lines = [
|
const lines = [
|
||||||
'# @ui-arch 私人组件库索引',
|
'# @ui-arch 私人组件库索引',
|
||||||
@@ -87,8 +98,8 @@ function cmdIndex() {
|
|||||||
for (const c of p.conventions ?? []) lines.push(`- 约定: ${c}`);
|
for (const c of p.conventions ?? []) lines.push(`- 约定: ${c}`);
|
||||||
lines.push('');
|
lines.push('');
|
||||||
}
|
}
|
||||||
fs.writeFileSync(LLMS_FILE, lines.join('\n'));
|
writeIfChanged(LLMS_FILE, lines.join('\n'));
|
||||||
console.log(`indexed ${packages.length} package(s) -> .ua/index.json, llms.txt`);
|
console.log(`indexed ${packages.length} package(s) -> .ua/index.json, llms.txt${changed ? '' : ' (unchanged, skip)'}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*** 读取注册表索引;缺失则报错退出 ***/
|
/*** 读取注册表索引;缺失则报错退出 ***/
|
||||||
|
|||||||
Reference in New Issue
Block a user