-
Notifications
You must be signed in to change notification settings - Fork 6
/
cli.js
38 lines (29 loc) · 1023 Bytes
/
cli.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
#!/usr/bin/env node
var fs = require('fs');
var GeojsonMinifier = require('./');
var argv = require('minimist')(process.argv.slice(2));
var operation = argv["o"];
var inputFile = argv["f"];
var precision = argv["p"];
if (!operation) {
console.log("Please specify operation(-o) (pack|unpack)");
process.exit();
}
if (!inputFile) {
console.log("Please specify path to inputFile(-f)");
process.exit();
}
var fileBefore = fs.readFileSync(inputFile);
console.log("File size before: " + Math.ceil(fileBefore.length/1024) + " kb");
var minifier = new GeojsonMinifier({ precision: precision });
var processed, filePrefix = "";
if (operation === "pack") {
filePrefix = ".packed";
processed = minifier.pack(JSON.parse(fileBefore))
} else {
filePrefix = ".unpacked";
processed = minifier.unpack(JSON.parse(fileBefore));
}
fs.writeFileSync(inputFile + filePrefix, processed);
var fileAfter = fs.readFileSync(inputFile + filePrefix);
console.log("File size after: " + Math.ceil(fileAfter.length/1024) + " kb");