Skip to content

Commit 9f1be08

Browse files
authored
Merge branch 'main' into dhower/issue171
2 parents 4c4b701 + 5f75f6a commit 9f1be08

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

index-unifieddb.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env node
2+
'use strict';
3+
4+
const process = require('process');
5+
const path = require('path');
6+
const fs = require('fs');
7+
8+
const { readdir, stat } = fs.promises;
9+
10+
const rec = async (branch, root) => {
11+
const node = {};
12+
const localPath = path.resolve(root, ...branch);
13+
const els = await readdir(localPath);
14+
for (const el of els) {
15+
const isFile = (await stat(path.resolve(localPath, el))).isFile();
16+
const fileExt = path.extname(el);
17+
const baseName = path.basename(el, fileExt);
18+
if (isFile) {
19+
if (['.yaml', '.json'].includes(fileExt)) {
20+
node[baseName] = {$ref: path.join(...branch, el)};
21+
}
22+
} else {
23+
node[el] = await rec([...branch, el], root);
24+
}
25+
}
26+
return node;
27+
};
28+
29+
const main = async () => {
30+
const [, , root] = process.argv;
31+
if (root === undefined) {
32+
console.error('usage: ./index-unifieddb.js <path-to-unifieddb-arch-folder>');
33+
return;
34+
}
35+
const rootPath = path.resolve('.', root);
36+
const tree = await rec([], rootPath);
37+
console.log(JSON.stringify(tree, null, 2));
38+
};
39+
40+
main();

0 commit comments

Comments
 (0)