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