|
| 1 | +#!/usr/bin/env node |
| 2 | +'use strict' |
| 3 | + |
| 4 | +const fs = require('fs') |
| 5 | +const path = require('path') |
| 6 | + |
| 7 | +const ROOT = path.resolve(__dirname, '..') |
| 8 | +const failures = [] |
| 9 | + |
| 10 | +function read(file) { |
| 11 | + return fs.readFileSync(path.join(ROOT, file), 'utf8') |
| 12 | +} |
| 13 | + |
| 14 | +function mustInclude(file, needle) { |
| 15 | + if (!read(file).includes(needle)) failures.push(`${file} missing "${needle}"`) |
| 16 | +} |
| 17 | + |
| 18 | +function mustExist(file) { |
| 19 | + if (!fs.existsSync(path.join(ROOT, file))) failures.push(`missing file: ${file}`) |
| 20 | +} |
| 21 | + |
| 22 | +function assertOrder(file, headings) { |
| 23 | + const text = read(file) |
| 24 | + let previous = -1 |
| 25 | + for (const heading of headings) { |
| 26 | + const index = text.indexOf(heading) |
| 27 | + if (index === -1) { |
| 28 | + failures.push(`${file} missing heading "${heading}"`) |
| 29 | + return |
| 30 | + } |
| 31 | + if (index < previous) { |
| 32 | + failures.push(`${file} heading order drift: "${heading}" appears before an earlier user-path section`) |
| 33 | + return |
| 34 | + } |
| 35 | + previous = index |
| 36 | + } |
| 37 | +} |
| 38 | + |
| 39 | +const plugin = JSON.parse(read('plugin.json')) |
| 40 | +for (const [id, file] of [ |
| 41 | + ['readme-authoring', 'skills/readme-authoring/SKILL.md'], |
| 42 | + ['audit-readme', 'skills/audit-readme/SKILL.md'] |
| 43 | +]) { |
| 44 | + mustExist(file) |
| 45 | + if (!plugin.skills.some(skill => skill.id === id && skill.file === file)) { |
| 46 | + failures.push(`plugin.json missing ${id} skill entry`) |
| 47 | + } |
| 48 | +} |
| 49 | + |
| 50 | +for (const [file, needle] of [ |
| 51 | + ['skills/readme-authoring/SKILL.md', 'primaryAudience'], |
| 52 | + ['skills/readme-authoring/SKILL.md', 'userJourney'], |
| 53 | + ['skills/readme-authoring/SKILL.md', 'consumerMap'], |
| 54 | + ['skills/readme-authoring/SKILL.md', '用户 / 使用者'], |
| 55 | + ['skills/audit-readme/SKILL.md', 'RM-1 用户路径完整性'], |
| 56 | + ['skills/audit-readme/SKILL.md', 'RM-6 消费链一致性'], |
| 57 | + ['skills/dev-docs/SKILL.md', 'readme-authoring'], |
| 58 | + ['skills/dev-docs/SKILL.md', 'audit-readme'], |
| 59 | + ['skills/dev-init/SKILL.md', 'readme-authoring'], |
| 60 | + ['skills/document-sync/SKILL.md', 'readme-authoring'], |
| 61 | + ['skills/document-sync/SKILL.md', 'audit-readme'], |
| 62 | + ['skills/audit-document/SKILL.md', 'audit-readme'], |
| 63 | + ['skills/audit-execution-guide/SKILL.md', 'audit-readme'], |
| 64 | + ['prompts/project-readme.prompt.md', '用户 / 使用者优先'], |
| 65 | + ['README.md', 'readme-authoring'], |
| 66 | + ['README.md', 'audit-readme'], |
| 67 | + ['website/docs/intro/index.md', 'readme-authoring'], |
| 68 | + ['website/docs/specs/directory-structure.md', 'audit-readme'] |
| 69 | +]) { |
| 70 | + mustInclude(file, needle) |
| 71 | +} |
| 72 | + |
| 73 | +assertOrder('prompts/project-readme.prompt.md', [ |
| 74 | + '## 项目简介', |
| 75 | + '## 适用对象与使用场景', |
| 76 | + '## 快速开始', |
| 77 | + '## 常见用法', |
| 78 | + '## 配置', |
| 79 | + '## 文档与接口', |
| 80 | + '## 常见问题与排错', |
| 81 | + '## 开发与贡献' |
| 82 | +]) |
| 83 | + |
| 84 | +const pkg = JSON.parse(read('package.json')) |
| 85 | +if (pkg.scripts['test:readme-governance'] !== 'node scripts/test-readme-governance.js') { |
| 86 | + failures.push('package.json missing test:readme-governance script') |
| 87 | +} |
| 88 | +if (!pkg.scripts['test:all'] || !pkg.scripts['test:all'].includes('node scripts/test-readme-governance.js')) { |
| 89 | + failures.push('package.json test:all missing readme governance targeted test') |
| 90 | +} |
| 91 | + |
| 92 | +if (failures.length) { |
| 93 | + console.error('README governance checks failed:') |
| 94 | + for (const failure of failures) console.error(`- ${failure}`) |
| 95 | + process.exit(1) |
| 96 | +} |
| 97 | + |
| 98 | +console.log('README governance checks passed') |
0 commit comments