-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.js
executable file
·49 lines (41 loc) · 1.09 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
#!/usr/bin/env node
'use strict'
const mri = require('mri')
const pkg = require('./package.json')
const argv = mri(process.argv.slice(2), {
boolean: [
'help', 'h',
'version', 'v',
]
})
if (argv.help || argv.h) {
process.stdout.write(`
Usage:
serve-gtfs-as-lc [options] [--] <todo>
Options:
--port -p Port to listen on. Defaults to $PORT or 3000.
Examples:
serve-gtfs-as-lc --port 8080
\n`)
process.exit(0)
}
if (argv.version || argv.v) {
process.stdout.write(`${pkg.name} v${pkg.version}\n`)
process.exit(0)
}
const {createServer} = require('http')
const {promisify} = require('util')
const gtfsLinkedConnectionsServer = require('.')
const port = parseInt(argv.port || argv.p || process.env.PORT || '3000')
;(async () => {
// todo: customisable {stop,connection,trip,route}Id()
const app = await gtfsLinkedConnectionsServer()
const server = createServer(app)
const pListen = promisify(server.listen.bind(server))
await pListen(port)
console.info(`Linked Connections server listening on port ${port}`)
})()
.catch((err) => {
console.error(err)
process.exit(1)
})