-
-
Notifications
You must be signed in to change notification settings - Fork 110
/
list-flows.js
42 lines (34 loc) · 999 Bytes
/
list-flows.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
const fs = require('fs')
const path = require('path')
const flows = {}
// Recursive function to read subfolders and files
function readSubfoldersAndFiles (directory) {
fs.readdirSync(directory).forEach(file => {
const fullPath = path.join('./', directory, file)
if (fs.lstatSync(fullPath).isDirectory()) {
readSubfoldersAndFiles(fullPath)
} else {
if (path.extname(fullPath) === '.js' && fullPath.indexOf('flows') !== -1) {
flows[fullPath] = require('./' + fullPath)
}
}
})
}
// convert Object to JSON formatted string
function formatJSON (obj) {
for (const data in obj) {
obj[data] = JSON.parse(JSON.stringify(obj[data]))
}
return obj
}
readSubfoldersAndFiles('./test')
// console.log(flows);
for (const flowEntry in flows) {
console.log(flowEntry)
const flowData = require('./' + flowEntry)
for (const flow in flowData) {
flowData[flow] = formatJSON(flowData[flow])
}
// console.log(flowData);
}
// console.log(flows);