Skip to content

Commit

Permalink
Create compiler.js
Browse files Browse the repository at this point in the history
  • Loading branch information
justinshannon committed Nov 19, 2022
1 parent d860ed7 commit 5da82a2
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions compiler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,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);
}
}
})
}

0 comments on commit 5da82a2

Please sign in to comment.