()
| 152 | } |
| 153 | |
| 154 | function main() { |
| 155 | process.chdir(ROOT); |
| 156 | |
| 157 | const verbose = |
| 158 | process.env.VERBOSE_TOC === "1" || |
| 159 | process.env.VERBOSE_TOC === "true" || |
| 160 | process.env.VERBOSE === "1" || |
| 161 | process.env.VERBOSE === "true"; |
| 162 | const maxMissing = |
| 163 | Number.parseInt(process.env.TOC_MAX_MISSING || "", 10) || 50; |
| 164 | const maxFiles = |
| 165 | Number.parseInt(process.env.TOC_MAX_FILES || "", 10) || 30; |
| 166 | const maxLinksPerFile = |
| 167 | Number.parseInt(process.env.TOC_MAX_LINKS_PER_FILE || "", 10) || 10; |
| 168 | |
| 169 | const tocFiles = readTocFiles(); |
| 170 | if (tocFiles.length === 0) { |
| 171 | console.error("TOC check error: no TOC*.md files found in repo root."); |
| 172 | process.exit(1); |
| 173 | } |
| 174 | |
| 175 | const { tocToPages, anyTocPages, pageToTocs, cloudTocPages } = |
| 176 | buildTocIndex(tocFiles); |
| 177 | const buildScopePages = sortedValues(anyTocPages); |
| 178 | |
| 179 | const missingScopePages = []; |
| 180 | const violations = []; |
| 181 | |
| 182 | buildScopePages.forEach((sourceRel) => { |
| 183 | const sourceAbs = path.join(ROOT, sourceRel); |
| 184 | if (!fs.existsSync(sourceAbs)) { |
| 185 | missingScopePages.push(sourceRel); |
| 186 | return; |
| 187 | } |
| 188 | |
| 189 | extractInternalDocTargetsFromMarkdownFile(sourceAbs) |
| 190 | .filter((targetRel) => |
| 191 | !SPECIAL_IMPLICIT_TARGETS.has(path.basename(targetRel)) |
| 192 | ) |
| 193 | .forEach((targetRel) => { |
| 194 | const { ok, expectedLabel } = expectedSetForTarget( |
| 195 | targetRel, |
| 196 | tocToPages, |
| 197 | anyTocPages, |
| 198 | cloudTocPages |
| 199 | ); |
| 200 | if (!ok) { |
| 201 | violations.push({ |
| 202 | sourceRel, |
| 203 | targetRel, |
| 204 | expectedLabel, |
| 205 | }); |
| 206 | } |
| 207 | }); |
| 208 | }); |
| 209 | |
| 210 | if (missingScopePages.length > 0) { |
| 211 | // Printed below in a grouped summary. |
no test coverage detected