forked from w3c/webref
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
44 lines (37 loc) · 921 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
const fs = require('fs').promises;
const path = require('path');
const WebIDL2 = require('webidl2');
class IDLFile {
constructor(dir, file) {
this.filename = file;
this.shortname = path.basename(file, '.idl');
this.path = path.join(dir, file);
}
async text() {
const text = await fs.readFile(this.path, 'utf8');
return text;
}
async parse() {
const text = await this.text();
return WebIDL2.parse(text);
}
}
async function listAll() {
const all = {};
const files = await fs.readdir(__dirname);
for (const f of files) {
if (f.endsWith('.idl')) {
const idlFile = new IDLFile(__dirname, f);
all[idlFile.shortname] = idlFile;
}
}
return all;
}
async function parseAll() {
const all = await listAll();
for (const [key, value] of Object.entries(all)) {
all[key] = await value.parse();
}
return all;
}
module.exports = {listAll, parseAll};