(dir, prefix = '')
| 174 | // - 子目录若有自己的 meta,则父级只需引用目录名,不下钻 |
| 175 | // - 子目录若无 meta,则父级须以 `subdir/file` 形式列出每个文件 |
| 176 | function collectExpectedSlugs(dir, prefix = '') { |
| 177 | const out = new Set(); |
| 178 | for (const entry of fs.readdirSync(dir, { withFileTypes: true })) { |
| 179 | if (entry.name.startsWith('.')) continue; |
| 180 | if (isMetaFile(entry.name)) continue; |
| 181 | |
| 182 | const full = path.join(dir, entry.name); |
| 183 | if (entry.isFile()) { |
| 184 | if (!/\.mdx?$/i.test(entry.name)) continue; |
| 185 | if (isIndexFile(entry.name)) continue; |
| 186 | const slug = slugFromFile(entry.name); |
| 187 | out.add(prefix ? `${prefix}/${slug}` : slug); |
| 188 | } else if (entry.isDirectory()) { |
| 189 | const childPrefix = prefix ? `${prefix}/${entry.name}` : entry.name; |
| 190 | if (dirHasMeta(full)) { |
| 191 | out.add(childPrefix); |
| 192 | } else { |
| 193 | for (const s of collectExpectedSlugs(full, childPrefix)) out.add(s); |
| 194 | } |
| 195 | } |
| 196 | } |
| 197 | return out; |
| 198 | } |
| 199 | |
| 200 | function checkMetaCoverage() { |
| 201 | const errors = []; |
no test coverage detected