iter: d24 重写 README + 组件清单防漂移校验
This commit is contained in:
@@ -576,15 +576,33 @@ function checkSkinCss(pkg) {
|
||||
return issues;
|
||||
}
|
||||
|
||||
/*** README 组件区块校验:marker 之间的 id 集合必须与全部清单的 docs.components 完全一致(防文档漂移) ***/
|
||||
function checkReadme(pkgs) {
|
||||
const issues = [];
|
||||
const file = path.join(ROOT, 'README.md');
|
||||
if (!fs.existsSync(file)) return issues; // 卫语句:没有 README 就不校验
|
||||
const block = fs.readFileSync(file, 'utf8').match(/<!-- ua:components -->([\s\S]*?)<!-- \/ua:components -->/);
|
||||
if (!block) {
|
||||
issues.push('README.md 缺少组件区块标记(<!-- ua:components --> … <!-- /ua:components -->)');
|
||||
return issues;
|
||||
}
|
||||
const listed = new Set(block[1].split('·').map((s) => s.trim()).filter(Boolean));
|
||||
const actual = new Set(pkgs.flatMap((p) => (p.docs?.components ?? []).map((c) => c.id)));
|
||||
for (const id of actual) if (!listed.has(id)) issues.push(`README.md 组件区块缺少 ${id}`);
|
||||
for (const id of listed) if (!actual.has(id)) issues.push(`README.md 组件区块多出 ${id}(清单里没有)`);
|
||||
return issues;
|
||||
}
|
||||
|
||||
/*** 清单一致性校验:组件文档块的 id / props 说明 / demo 锚点必须与代码和演示产物对齐 ***/
|
||||
function cmdVerify() {
|
||||
const issues = [];
|
||||
const pkgs = collectManifests(); // 一次收集,供组件校验与 README 区块校验共用
|
||||
const demoPath = path.join(ROOT, 'apps', 'demo', 'main.ts'); // 演示区块定义在源码里(产物是打包后的 JS)
|
||||
const demoSource = fs.existsSync(demoPath) ? fs.readFileSync(demoPath, 'utf8') : '';
|
||||
const anchors = new Set(demoSource.match(/sec-[a-z0-9-]+/g) ?? []); // 已定义的区块锚点
|
||||
if (!demoSource) console.log('verify: 未找到 apps/demo/main.ts,跳过 demo 锚点校验');
|
||||
|
||||
for (const pkg of collectManifests()) {
|
||||
for (const pkg of pkgs) {
|
||||
const comps = pkg.docs?.components ?? []; // 清单已被 collectManifests 摊平
|
||||
const exports = pkg.api?.exports ?? [];
|
||||
if (pkg.type === 'skin-dom') issues.push(...checkSkinCss(pkg));
|
||||
@@ -610,12 +628,14 @@ function cmdVerify() {
|
||||
}
|
||||
}
|
||||
|
||||
issues.push(...checkReadme(pkgs));
|
||||
|
||||
if (issues.length) {
|
||||
for (const it of issues) console.error('verify: ' + it);
|
||||
console.error(`${issues.length} violation(s)`);
|
||||
process.exit(1);
|
||||
}
|
||||
console.log('verify OK (manifest ↔ docs ↔ demo 一致,皮肤无硬编码颜色)');
|
||||
console.log('verify OK (manifest ↔ docs ↔ demo 一致,皮肤无硬编码颜色,README 组件清单同步)');
|
||||
}
|
||||
|
||||
// ---- 入口 ----
|
||||
|
||||
Reference in New Issue
Block a user