(corpusDir: string)
| 27 | * (`bundle-corpus.ts`); keeping it in one place prevents the two from drifting |
| 28 | * (a divergence would silently change rule precedence). */ |
| 29 | export function readCorpusDocs(corpusDir: string): RubiRuleDoc[] { |
| 30 | const docs: RubiRuleDoc[] = []; |
| 31 | (function walk(dir: string): void { |
| 32 | for (const e of fs |
| 33 | .readdirSync(dir, { withFileTypes: true }) |
| 34 | .sort((a, b) => a.name.localeCompare(b.name))) { |
| 35 | const p = path.join(dir, e.name); |
| 36 | if (e.isDirectory()) walk(p); |
| 37 | else if (e.name.endsWith('.json')) |
| 38 | docs.push(JSON.parse(fs.readFileSync(p, 'utf8')) as RubiRuleDoc); |
| 39 | } |
| 40 | })(corpusDir); |
| 41 | return docs; |
| 42 | } |
| 43 | |
| 44 | /** Load and compile all corpus files under a section directory, in order. */ |
| 45 | export function compileSection( |
no test coverage detected