-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathbuild.js
40 lines (36 loc) · 1.14 KB
/
build.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
const fs = require("fs");
const path = require("path");
async function* walk(dir, ext) {
for await (const d of await fs.promises.opendir(dir)) {
const entry = path.join(dir, d.name);
if (d.isDirectory()) {
yield* walk(entry, ext);
} else if (d.isFile() && (!ext || ext.test(path.extname(d.name)))) {
yield entry;
}
}
}
// Then, use it with a simple async for loop
async function main() {
const configs = [];
for await (const p of walk("config_templates", /\.ya?ml$/)) {
configs.push(p);
}
const samples = [];
for await (const p of walk("sample_data")) {
samples.push(p);
}
const sample_data_previews = [];
for await (const p of walk("sample_data_previews")) {
sample_data_previews.push(p);
}
/*
Files whose first comment is `# deprecated: This configuration will be deprecated soon. <additional message>` are deprecated and filtered from the manifest
*/
const templates = configs.filter((template) => {
const str = fs.readFileSync(template, "utf8");
return !str.startsWith("# deprecated");
});
console.log(JSON.stringify({ templates, samples, sample_data_previews }));
}
main();