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 = { 27 'all.json': true, 28 'index.json': true 29}; 30 31// Extract (and concatenate) the selected data from each document. 32// Expand hrefs found in json to include source HTML file. 33for (const link of toc.match(/<a.*?>/g)) { 34 const href = /href="(.*?)"/.exec(link)[1]; 35 const json = href.replace('.html', '.json'); 36 if (!jsonFiles.includes(json) || seen[json]) continue; 37 const data = JSON.parse( 38 fs.readFileSync(new URL(`./${json}`, source), 'utf8') 39 .replace(/<a href=\\"#/g, `<a href=\\"${href}#`) 40 ); 41 42 for (const property in data) { 43 if (results.hasOwnProperty(property)) { 44 data[property].forEach((mod) => { 45 mod.source = data.source; 46 }); 47 results[property].push(...data[property]); 48 } 49 } 50 51 // Mark source as seen. 52 seen[json] = true; 53} 54 55// Write results. 56fs.writeFileSync(new URL('./all.json', source), 57 `${JSON.stringify(results, null, 2)}\n`, 'utf8'); 58