({ repoRoot = process.cwd(), files = README_FILES } = {})
| 272 | |
| 273 | // BLOCKING. Returns a process exit code (0 ok, 1 on divergence). |
| 274 | function runReadmeCheck({ repoRoot = process.cwd(), files = README_FILES } = {}) { |
| 275 | const loaded = []; |
| 276 | let missing = 0; |
| 277 | for (const name of files) { |
| 278 | try { |
| 279 | loaded.push({ name, content: fs.readFileSync(path.join(repoRoot, name), "utf8") }); |
| 280 | } catch (e) { |
| 281 | missing++; |
| 282 | emitError(name, `Expected README translation file ${name} is missing.`); |
| 283 | } |
| 284 | } |
| 285 | |
| 286 | // Short-circuit when any expected file is absent: comparing only the files |
| 287 | // that DID load can mask a real divergence (e.g. a missing reference would |
| 288 | // silently promote the next file to reference). A missing translation is |
| 289 | // itself a failure, so fail fast before the structure comparison. |
| 290 | if (missing > 0) { |
| 291 | emitError( |
| 292 | null, |
| 293 | "README translation structure check failed: one or more expected " + |
| 294 | "README*.md files are missing (see the file annotations above)." |
| 295 | ); |
| 296 | return 1; |
| 297 | } |
| 298 | |
| 299 | const { ok, errors } = compareReadmeStructures(loaded); |
| 300 | for (const err of errors) emitError(err.file, err.message); |
| 301 | |
| 302 | if (ok) { |
| 303 | console.log( |
| 304 | `README translation structure check passed: all ${loaded.length} ` + |
| 305 | `README files share the same ## section structure.` |
| 306 | ); |
| 307 | return 0; |
| 308 | } |
| 309 | emitError( |
| 310 | null, |
| 311 | "README translation structure check failed. All README*.md files must " + |
| 312 | "share an identical ## section structure." |
| 313 | ); |
| 314 | return 1; |
| 315 | } |
| 316 | |
| 317 | // NON-BLOCKING. Always returns exit code 0; only emits `::warning` annotations. |
| 318 | function runDocsCheck({ env = process.env } = {}) { |
no test coverage detected