-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathutils.js
53 lines (49 loc) · 1.66 KB
/
utils.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
43
44
45
46
47
48
49
50
51
52
53
'use strict';
const fs = require('fs');
/**
* Merge a configuration with tileset objects and
* set 'smart' defaults based on these sources, e.g. center, zoom
* @param {object} config passed to the mbview server
* @param {array} tilesets of objects extracted from the mbtiles
* @return {object} updated config object with sources appended
*/
module.exports.mergeConfigurations = function (config, tilesets) {
const tilehash = tilesets.reduce((prev, curr) => {
const c = {};
c[curr.basename] = curr;
return Object.assign({}, prev, c);
}, {});
const smart = Object.assign({}, config, tilesets[0]);
const centerZoom = smart.center.pop();
smart.zoom = smart.zoom || centerZoom;
smart.center.push(smart.zoom);
return Object.assign({}, smart, {
sources: tilehash
});
};
/**
* Get usage instructions
* @return {String} the instructions to run this thing
*/
module.exports.usage = function () {
const u = [];
u.push('usage: mbview [options] [files]');
u.push('');
u.push(' --port sets port to use (default: 3000)');
u.push(' --host sets host to use (default: localhost)');
u.push(' --quiet or -q supress all logging except the address to visit');
u.push(' -n don\'t automatically open the browser on start');
u.push(' --basemap, --base or --map sets the basemap style (default: dark)');
u.push(' --version returns module version');
u.push(' --help prints this message');
u.push('');
return u.join('\n');
};
/**
* Get module version from the package.json file
* @return {String} version number
*/
module.exports.version = function () {
const data = fs.readFileSync(__dirname + '/package.json');
return JSON.parse(data).version;
};