Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
mohamedkhallouq
GitHub Repository: mohamedkhallouq/content
Path: blob/main/scripts/update-interface-data.js
6476 views
1
import fs from "node:fs/promises";
2
import path from "node:path";
3
4
if (!process.argv[2]) {
5
console.error("Required argument: path to webref checkout");
6
process.exit(2);
7
}
8
9
const webrefPath = path.join(process.argv[2], "ed");
10
const idlnames = await fs
11
.readFile(path.join(webrefPath, "idlnames.json"), "utf-8")
12
.then(JSON.parse);
13
14
const idls = await Promise.all(
15
Object.entries(idlnames)
16
.sort(([k1], [k2]) => k1.localeCompare(k2))
17
.map(([, { parsed: jsonIdlPath }]) =>
18
fs.readFile(path.join(webrefPath, jsonIdlPath), "utf-8").then(JSON.parse)
19
)
20
);
21
22
const interfaceData = idls.reduce((interfaceData, idl) => {
23
if (idl.type === "interface") {
24
interfaceData[idl.name] = {
25
inh: idl.inheritance?.name || "",
26
impl: [],
27
};
28
}
29
return interfaceData;
30
}, {});
31
32
await fs.writeFile(
33
"files/jsondata/InterfaceData.json",
34
JSON.stringify([interfaceData], null, 2) + "\n"
35
);
36
37