-
-
Notifications
You must be signed in to change notification settings - Fork 91
/
compiler.js
42 lines (37 loc) · 1.23 KB
/
compiler.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');
var template = { type: "FeatureCollection", name: "fix", crs: { type: "name", properties: { name: "urn:ogc:def:crs:OGC:1.3:CRS84" } }, features: [] }
const files = [];
traverseDir(path.join(__dirname, "Boundaries"));
let promises = files.map(function(value, index) {
return new Promise(function(resolve) {
fs.readFile(value, 'utf8', (err, data) => {
if (err) {
console.error(err);
return;
}
template.features.push(JSON.parse(data));
resolve();
})
})
})
Promise.all(promises).then(function() {
fs.writeFile(__dirname + "/TRACONBoundaries.geojson", JSON.stringify(template), err => {
if (err) {
console.error(err);
}
});
});
function traverseDir(dir) {
fs.readdirSync(dir).forEach(file => {
let fullPath = path.join(dir, file);
if (fs.lstatSync(fullPath).isDirectory()) {
traverseDir(fullPath);
} else {
if (!path.dirname(fullPath).toLowerCase().includes("node_modules") &&
path.extname(fullPath).toLowerCase() === ".json") {
files.push(fullPath);
}
}
})
}