Add @webref/idl dependency
Signed-off-by: Victor Porof <victorporof@chromium.org>
Bug: 1325812
Change-Id: I044170880d20ce0402062755787cccafd63c6a42
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/3695370
Reviewed-by: Mathias Bynens <mathias@chromium.org>
diff --git a/node_modules/@webref/idl/index.js b/node_modules/@webref/idl/index.js
new file mode 100644
index 0000000..9910d0c
--- /dev/null
+++ b/node_modules/@webref/idl/index.js
@@ -0,0 +1,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({folder = __dirname} = {}) {
+ const all = {};
+ const files = await fs.readdir(folder);
+ for (const f of files) {
+ if (f.endsWith('.idl')) {
+ const idlFile = new IDLFile(folder, f);
+ all[idlFile.shortname] = idlFile;
+ }
+ }
+ return all;
+}
+
+async function parseAll(options) {
+ const all = await listAll(options);
+ for (const [key, value] of Object.entries(all)) {
+ all[key] = await value.parse();
+ }
+ return all;
+}
+
+module.exports = {listAll, parseAll};