generated from Exabyte-io/template-definitions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_workflows.js
60 lines (54 loc) · 1.82 KB
/
build_workflows.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
const fs = require("fs");
const path = require("path");
const yaml = require("js-yaml");
const allApplications = [
"espresso",
"jupyterLab",
"exabyteml",
"nwchem",
"python",
"shell",
"vasp",
"deepmd",
];
const allWorkflows = { workflows: {}, subworkflows: {} };
const JSONstringifyOrder = (obj, space) => {
const allKeys = new Set();
// eslint-disable-next-line no-sequences
JSON.stringify(obj, (key, value) => (allKeys.add(key), value));
return JSON.stringify(obj, Array.from(allKeys).sort(), space);
};
const loadFile = (name, dir, file, type) => {
const obj = fs.readFileSync(path.resolve(dir, file), "utf8");
const key = file.split(".")[0];
allWorkflows[type][name][key] = yaml.load(obj);
};
allApplications.forEach((name) => {
allWorkflows.workflows[name] = {};
allWorkflows.subworkflows[name] = {};
const wfDir = path.resolve(__dirname, "assets", "workflows", name);
const swDir = path.resolve(__dirname, "assets", "subworkflows", name);
try {
const wfFiles = fs.readdirSync(wfDir);
const swFiles = fs.readdirSync(swDir);
console.log(
`Building ${name}: ${wfFiles.length} workflow(s) and ${swFiles.length} subworkflow(s)`,
);
wfFiles.forEach((file) => loadFile(name, wfDir, file, "workflows"));
swFiles.forEach((file) => loadFile(name, swDir, file, "subworkflows"));
} catch (e) {
console.log(e);
}
});
const write_path = "workflows.js";
// write to src for unit test coverage simplicity
fs.writeFileSync(
`./src/workflows/${write_path}`,
"module.exports = {workflowData: " + JSONstringifyOrder(allWorkflows) + "}",
"utf8",
);
fs.writeFileSync(
`./dist/workflows/${write_path}`,
"module.exports = {workflowData: " + JSONstringifyOrder(allWorkflows) + "}",
"utf8",
);