-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbundle.js
More file actions
39 lines (34 loc) · 1.16 KB
/
bundle.js
File metadata and controls
39 lines (34 loc) · 1.16 KB
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
const $RefParser = require("@apidevtools/json-schema-ref-parser");
const fs = require("fs");
const path = require("path");
function getFilesAtDepth(directory, depth = 1, currentDepth = 0, files = []) {
const items = fs.readdirSync(directory);
items.forEach((item) => {
const itemPath = "./" + path.join(directory, item);
const stats = fs.statSync(itemPath);
// Check if item is a directory or a file
if (stats.isDirectory()) {
// Traverse deeper if it's a directory
getFilesAtDepth(itemPath, depth, currentDepth + 1, files);
} else if (currentDepth >= depth) {
// Add file to list if it's at the required depth
files.push(itemPath);
}
});
return files;
}
const relativePath = "./schemas";
const depthRequirement = 1; // Minimum depth for files to be included
getFilesAtDepth(relativePath, depthRequirement).forEach(async (file) => {
try {
const deref = await $RefParser.bundle(`./${file}`);
fs.writeFile(file, JSON.stringify(deref), (err) => {
if (err) console.log(err);
else {
console.log(`File written successfully: ${file}`);
}
});
} catch (err) {
console.error(err);
}
});