-
Notifications
You must be signed in to change notification settings - Fork 73
/
cli.js
executable file
·54 lines (44 loc) · 1.28 KB
/
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env node
/* eslint-disable no-console */
'use strict';
const argv = require('minimist')(process.argv.slice(2), {
boolean: ['n', 'quiet', 'q']
});
const open = require('open');
const fs = require('fs');
const utils = require('./utils');
const mbtiles = argv._;
const accessToken = argv.MapboxAccessToken ||
process.env.MAPBOX_ACCESS_TOKEN ||
process.env.MapboxAccessToken;
if (argv.version || argv.v) {
console.log(utils.version());
process.exit(0);
} else if (!mbtiles.length) {
console.log(utils.usage());
process.exit(1);
} else if (!accessToken) {
console.log('missing access token, try `export MAPBOX_ACCESS_TOKEN=...`');
process.exit(1);
}
try {
mbtiles.forEach((f) => { fs.statSync(f).isFile(); });
} catch (e) {
return console.error(e);
}
argv.basemap = argv.basemap || argv.base || argv.map || 'dark';
const MBView = require('./mbview');
const params = {
center: argv.center || [-122.42, 37.75],
mbtiles: mbtiles,
host: argv.host || 'localhost',
port: argv.port || 3000,
zoom: 12,
quiet: argv.q || argv.quiet,
basemap: argv.basemap,
accessToken: accessToken
};
MBView.serve(params, (err, config) => {
console.log('Listening on http://' + config.host + ':' + config.port);
if (!argv.n) open('http://' + config.host + ':' + config.port);
});