11#!/usr/bin/env node
22
3- const fs = require ( 'fs' ) ;
4- const GtfsIndex = require ( '../lib/GtfsIndex' ) ;
5- const Gtfsrt2LC = require ( '../lib/Gtfsrt2LC' ) ;
6- const { Level } = require ( 'level' ) ;
7- const program = require ( 'commander' ) ;
3+ import fs from 'fs' ;
4+ import { GtfsIndex } from '../lib/GtfsIndex.js' ;
5+ import { Gtfsrt2LC } from '../lib/Gtfsrt2LC.js' ;
6+ import { Level } from 'level' ;
7+ import { program } from 'commander' ;
88
99program
1010 . option ( '-r --real-time <realTime>' , 'URL/path to gtfs-rt feed' )
@@ -18,40 +18,40 @@ program
1818 . option ( '-h --history <history>' , 'Path to historic Connection LevelStore for differential updates' )
1919 . parse ( process . argv ) ;
2020
21- if ( ! program . realTime ) {
21+ if ( ! program . opts ( ) . realTime ) {
2222 console . error ( 'Please provide a url or a path to a GTFS-RT feed' ) ;
2323 console . error ( "GTFS-RT to linked connections converter use --help to discover how to use it" ) ;
2424 process . exit ( ) ;
2525}
2626
27- if ( ! program . static ) {
27+ if ( ! program . opts ( ) . static ) {
2828 console . error ( 'Please provide a url or a path to a GTFS feed' ) ;
2929 console . error ( "GTFS-RT to linked connections converter use --help to discover how to use it" ) ;
3030 process . exit ( ) ;
3131}
3232
33- if ( ! program . store ) {
34- program . store = 'MemStore' ;
33+ if ( ! program . opts ( ) . store ) {
34+ program . opts ( ) . store = 'MemStore' ;
3535}
3636
3737// Load URIs template
3838let template = null ;
3939try {
40- if ( program . urisTemplate ) {
41- template = JSON . parse ( fs . readFileSync ( program . urisTemplate , 'utf8' ) ) ;
40+ if ( program . opts ( ) . urisTemplate ) {
41+ template = JSON . parse ( fs . readFileSync ( program . opts ( ) . urisTemplate , 'utf8' ) ) ;
4242 }
4343} catch ( err ) {
4444 console . error ( 'Please provide a valid path to a template file' ) ;
4545 console . error ( "GTFS-RT to linked connections converter use --help to discover how to use it" ) ;
4646 process . exit ( ) ;
4747}
4848// Get resulting data format
49- const format = program . format || 'json' ;
49+ const format = program . opts ( ) . format || 'json' ;
5050// Set HTTP custom headers, e.g., API keys
5151let headers = { } ;
52- if ( program . headers ) {
52+ if ( program . opts ( ) . headers ) {
5353 try {
54- headers = JSON . parse ( program . headers ) ;
54+ headers = JSON . parse ( program . opts ( ) . headers ) ;
5555 } catch ( err ) {
5656 console . error ( err ) ;
5757 console . error ( 'Please provide a valid JSON string for the extra HTTP headers' ) ;
@@ -62,13 +62,13 @@ if (program.headers) {
6262
6363// Load historic connections store (if any)
6464let historyDB = null ;
65- if ( program . history ) {
66- historyDB = new Level ( program . history , { valueEncoding : 'json' } ) ;
65+ if ( program . opts ( ) . history ) {
66+ historyDB = new Level ( program . opts ( ) . history , { valueEncoding : 'json' } ) ;
6767}
6868
6969let t0 = new Date ( ) ;
70- const gtfsrt2lc = new Gtfsrt2LC ( { path : program . realTime , uris : template , headers : headers } ) ;
71- const gtfsIndexer = new GtfsIndex ( { path : program . static , headers : headers } ) ;
70+ const gtfsrt2lc = new Gtfsrt2LC ( { path : program . opts ( ) . realTime , uris : template , headers : headers } ) ;
71+ const gtfsIndexer = new GtfsIndex ( { path : program . opts ( ) . static , headers : headers } ) ;
7272
7373async function processUpdate ( store , grep , deduce ) {
7474 console . error ( "Converting the GTFS-RT feed to Linked Connections" ) ;
@@ -99,4 +99,4 @@ async function processUpdate(store, grep, deduce) {
9999 }
100100}
101101
102- processUpdate ( program . store , program . grep , program . deduce ) ;
102+ processUpdate ( program . opts ( ) . store , program . opts ( ) . grep , program . opts ( ) . deduce ) ;
0 commit comments