mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-10-05 11:31:31 +08:00
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>
45 lines
954 B
JavaScript
45 lines
954 B
JavaScript
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};
|