-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserve.js
executable file
·72 lines (63 loc) · 1.41 KB
/
serve.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
70
71
72
#!/usr/bin/env node
'use strict'
const {parseArgs} = require('util')
const pkg = require('./package.json')
const {
values: flags,
} = parseArgs({
options: {
'help': {
type: 'boolean',
short: 'h',
},
'version': {
type: 'boolean',
short: 'v',
},
'feed-info': {
type: 'string',
short: 'i',
},
'feed-url': {
type: 'string',
short: 'u',
},
'signal-demand': {
type: 'boolean',
short: 'd',
},
},
})
if (flags.help) {
process.stdout.write(`
Usage:
serve-as-gtfs-rt
Options:
--feed-info -i Path to GTFS-Static feed_info.txt file.
--feed-url -u Direct download URL of the GTFS-Static feed used.
--signal-demand -d Signal demand in fresh data to the monitor component.
Examples:
serve-as-gtfs-rt
\n`)
process.exit(0)
}
if (flags.version) {
process.stdout.write(`${pkg.name} v${pkg.version}\n`)
process.exit(0)
}
const {accessSync, constants} = require('fs')
const serveGtfsRtViaHttp = require('./lib/serve')
// todo [breaking]: rename to --static-feed-info
const pathToStaticFeedInfo = flags['feed-info'] || null
if (pathToStaticFeedInfo) {
// check if file is readable
accessSync(pathToStaticFeedInfo, constants.R_OK)
}
// todo [breaking]: rename to --static-feed-url
const staticFeedUrl = flags['feed-url'] || null
const signalDemand = !!flags['signal-demand']
serveGtfsRtViaHttp({
pathToStaticFeedInfo,
staticFeedUrl,
signalDemand,
})