forked from stevage/node-tippecanoe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
41 lines (36 loc) · 1.11 KB
/
index.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
const shell = require('shelljs'),
kebabCase = require('kebab-case');
function shellExec(cmd, echo) {
if (echo) {
const colors = require('colors');
console.log(cmd.green);
}
shell.exec(cmd);
return cmd;
}
function tippecanoe(layerFiles, params, options = {}) {
function quotify(s) {
s = String(s);
return s.match(/\s/) ? `'${s}'` : s;
}
function makeParam(key, value) {
if (Array.isArray(value)) {
return value.map(v => makeParam(key, v)).join(' ');
}
const param = '--' + kebabCase(key);
if (value === false) {
return '';
} else if (value === true) {
return param;
} else {
return param + `=${quotify(value)}`
}
}
let paramsStr = Object.keys(params)
.map(k => makeParam(k, params[k]))
.filter(Boolean)
.join(' ');
layerFiles = !Array.isArray(layerFiles) ? [layerFiles] : layerFiles;
return shellExec(`tippecanoe ${paramsStr} ${layerFiles.map(quotify).join(' ')}`, options.echo);
}
module.exports = tippecanoe;