1// Build all.json by combining the miscs, modules, classes, globals, and methods 2// from the generated json files. 3 4import fs from 'fs'; 5 6const source = new URL('../../out/doc/api/', import.meta.url); 7 8// Get a list of generated API documents. 9const jsonFiles = fs.readdirSync(source, 'utf8') 10 .filter((name) => name.includes('.json') && name !== 'all.json'); 11 12// Read the table of contents. 13const toc = fs.readFileSync(new URL('./index.html', source), 'utf8'); 14 15// Initialize results. Only these four data values will be collected. 16const results = { 17 miscs: [], 18 modules: [], 19 classes: [], 20 globals: [], 21 methods: [], 22}; 23 24// Identify files that should be skipped. As files are processed, they 25// are added to this list to prevent dupes. 26const seen = new Set(['all.json', 'index.json']); 27 28// Extract (and concatenate) the selected data from each document. 29// Expand hrefs found in json to include source HTML file. 30for (const link of toc.match(/<a.*?>/g)) { 31 const href = /href="(.*?)"/.exec(link)[1]; 32 const json = href.replace('.html', '.json'); 33 if (!jsonFiles.includes(json) || seen.has(json)) continue; 34 const data = JSON.parse( 35 fs.readFileSync(new URL(`./${json}`, source), 'utf8') 36 .replace(/<a href=\\"#/g, `<a href=\\"${href}#`), 37 ); 38 39 for (const property in data) { 40 if (Object.hasOwn(results, property)) { 41 data[property].forEach((mod) => { 42 mod.source = data.source; 43 }); 44 results[property].push(...data[property]); 45 } 46 } 47 48 // Mark source as seen. 49 seen.add(json); 50} 51 52// Write results. 53fs.writeFileSync(new URL('./all.json', source), 54 `${JSON.stringify(results, null, 2)}\n`, 'utf8'); 55