MCPcopy Index your code
hub / github.com/labring/FastGPT / collectExpectedSlugs

Function collectExpectedSlugs

document/script/checkDocRefs.js:176–198  ·  view source on GitHub ↗
(dir, prefix = '')

Source from the content-addressed store, hash-verified

174// - 子目录若有自己的 meta,则父级只需引用目录名,不下钻
175// - 子目录若无 meta,则父级须以 `subdir/file` 形式列出每个文件
176function 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
200function checkMetaCoverage() {
201 const errors = [];

Callers 1

checkMetaCoverageFunction · 0.85

Calls 8

isMetaFileFunction · 0.85
isIndexFileFunction · 0.85
slugFromFileFunction · 0.85
dirHasMetaFunction · 0.85
testMethod · 0.80
startsWithMethod · 0.45
joinMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected