2018-07-03 16:46:56 +00:00
|
|
|
// Build all.json by combining the miscs, modules, classes, globals, and methods
|
|
|
|
// from the generated json files.
|
|
|
|
|
2021-06-08 10:44:33 +00:00
|
|
|
import fs from 'fs';
|
2018-07-03 16:46:56 +00:00
|
|
|
|
2021-06-08 10:44:33 +00:00
|
|
|
const source = new URL('../../out/doc/api/', import.meta.url);
|
2018-07-03 16:46:56 +00:00
|
|
|
|
|
|
|
// Get a list of generated API documents.
|
|
|
|
const jsonFiles = fs.readdirSync(source, 'utf8')
|
|
|
|
.filter((name) => name.includes('.json') && name !== 'all.json');
|
|
|
|
|
|
|
|
// Read the table of contents.
|
2021-06-08 10:44:33 +00:00
|
|
|
const toc = fs.readFileSync(new URL('./index.html', source), 'utf8');
|
2018-07-03 16:46:56 +00:00
|
|
|
|
|
|
|
// Initialize results. Only these four data values will be collected.
|
|
|
|
const results = {
|
|
|
|
miscs: [],
|
|
|
|
modules: [],
|
|
|
|
classes: [],
|
|
|
|
globals: [],
|
2022-12-18 16:39:39 +00:00
|
|
|
methods: [],
|
2018-07-03 16:46:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Identify files that should be skipped. As files are processed, they
|
|
|
|
// are added to this list to prevent dupes.
|
2022-01-28 16:41:16 +00:00
|
|
|
const seen = new Set(['all.json', 'index.json']);
|
2018-07-03 16:46:56 +00:00
|
|
|
|
|
|
|
// Extract (and concatenate) the selected data from each document.
|
|
|
|
// Expand hrefs found in json to include source HTML file.
|
|
|
|
for (const link of toc.match(/<a.*?>/g)) {
|
|
|
|
const href = /href="(.*?)"/.exec(link)[1];
|
|
|
|
const json = href.replace('.html', '.json');
|
2022-01-28 16:41:16 +00:00
|
|
|
if (!jsonFiles.includes(json) || seen.has(json)) continue;
|
2018-07-03 16:46:56 +00:00
|
|
|
const data = JSON.parse(
|
2021-06-08 10:44:33 +00:00
|
|
|
fs.readFileSync(new URL(`./${json}`, source), 'utf8')
|
2022-12-18 16:39:39 +00:00
|
|
|
.replace(/<a href=\\"#/g, `<a href=\\"${href}#`),
|
2018-07-03 16:46:56 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
for (const property in data) {
|
2021-12-26 02:24:34 +00:00
|
|
|
if (Object.hasOwn(results, property)) {
|
2020-11-22 09:39:25 +00:00
|
|
|
data[property].forEach((mod) => {
|
|
|
|
mod.source = data.source;
|
|
|
|
});
|
2018-07-03 16:46:56 +00:00
|
|
|
results[property].push(...data[property]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Mark source as seen.
|
2022-01-28 16:41:16 +00:00
|
|
|
seen.add(json);
|
2018-07-03 16:46:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Write results.
|
2021-06-08 10:44:33 +00:00
|
|
|
fs.writeFileSync(new URL('./all.json', source),
|
2018-07-03 16:46:56 +00:00
|
|
|
`${JSON.stringify(results, null, 2)}\n`, 'utf8');
|