-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
cli.js
executable file
·48 lines (41 loc) · 915 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
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env node
'use strict'
const mri = require('mri')
const toString = require('virtual-dom-stringify')
const pkg = require('./package.json')
const generate = require('.')
const argv = mri(process.argv.slice(2), {
boolean: ['help', 'h', 'version', 'v']
})
if (argv.help || argv.h) {
process.stdout.write(`
Usage:
generate-vbb-transit-map
Examples:
cat graph.json | generate-vbb-transit-map > map.svg
\n`)
process.exit(0)
}
if (argv.version || argv.v) {
process.stdout.write(`generate-vbb-transit-map v${pkg.version}\n`)
process.exit(0)
}
const showError = (err) => {
console.error(err)
process.exit(1)
}
let input = ''
process.stdin
.on('error', showError)
.on('data', (d) => {
input += d.toString('utf8')
})
.once('end', () => {
try {
const graph = JSON.parse(input)
const svg = generate(graph)
process.stdout.write(toString(svg))
} catch (err) {
return showError(err)
}
})