-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
cli.js
executable file
·69 lines (61 loc) · 1.96 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#! /usr/bin/env node
import { URL } from 'url';
import fs from 'fs';
import path from 'path';
import TileBase from './tilebase.js';
import minimist from 'minimist';
const argv = minimist(process.argv, {
boolean: ['help', 'version']
});
if (argv.version) version();
else if (argv.help || !argv._[2]) help();
else if (argv._[2] === 'convert') convert();
function help() {
if (!argv._[2]) {
console.log();
version();
console.log();
console.log('Usage:');
console.log(' tilebase <subcommand> [--help] [--version]');
console.log();
console.log('Subcommands:');
console.log(' convert Convert an MBTiles file to TileBase');
console.log();
} else if (argv._[2] === 'convert') {
console.log();
console.log('Usage:');
console.log(' tilebase convert <input.mbtiles> <output.tilebase> [--help]');
console.log();
console.log('Parameters:');
console.log(' <input.mbtiles> Input MBTiles File');
console.log(' <output.tilebase> Output TileBase File');
console.log();
} else {
console.log('Unknown Subcommand');
process.exit(1);
}
}
function version() {
const pkg = JSON.parse(fs.readFileSync(new URL('package.json', import.meta.url).pathname));
console.log(`TileBase@${pkg.version}`);
}
async function convert() {
if (!argv._[3] || !argv._[4]) {
console.log('<input.mbtiles> and <output.tilebase> required');
process.exit(1);
}
try {
const tb = await TileBase.to_tb(
path.resolve(process.cwd(), argv._[3]),
path.resolve(process.cwd(), argv._[4])
);
await tb.open();
console.log('Success');
console.log(`${(tb.start_tile - tb.start_index) / 16} tiles`);
console.log(`${tb.start_tile} byte index`);
await tb.close();
} catch (err) {
console.error(err);
process.exit(1);
}
}