-
Notifications
You must be signed in to change notification settings - Fork 0
/
directorymanager.js
61 lines (52 loc) · 1.82 KB
/
directorymanager.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright 2024 Joseph P Medley
'use strict';
const fs = require('fs');
const { FileProcessor } = require('./fileprocessor.js');
const { initiateLogger } = require('./log.js');
const { InterfaceSet } = require('./interfaceset.js');
const EXCLUSIONS = ['inspector','testing','typed_arrays'];
initiateLogger(global.__commandName);
class DirectoryManager {
constructor(rootDirectory = 'idl/', options = { types: ['interface']} ) {
this._root = rootDirectory;
this._types = options.types;
}
_processDirectory(root) {
const contents = fs.readdirSync(root, {withFileTypes: true});
for (let c in contents) {
if (contents[c].isDirectory()) {
if (EXCLUSIONS.includes(contents[c].name)) { continue; }
this._processDirectory(`${root}${contents[c].name}/`);
} else if (contents[c].isFile()) {
if (!contents[c].name.endsWith('.idl')) { continue; }
if (contents[c].name.startsWith('test_')) { continue; }
try {
let fp = new FileProcessor(`${root}${contents[c].name}`);
fp.process((result) => {
if (this._types.includes(result.type)) {
if (!result.inTest) {
this._interfaceSet.add(result);
}
}
});
} catch (error) {
global.__logger.info(`Cannot process ${root}${contents[c].name}.`);
}
}
}
}
get interfaceSet() {
if (!this._interfaceSet) {
this._interfaceSet = new InterfaceSet();
this._processDirectory(this._root);
if (this._interfaceSet.count < 1) {
let msg = `IDL files were not found in ${this._root}. `
msg += `Run "npm run update-data -- -s" and try again.`;
console.log(msg);
process.exit();
}
}
return this._interfaceSet;
}
}
module.exports.DirectoryManager = DirectoryManager;