diff --git a/Gtfsrt2LC.js b/Gtfsrt2LC.js deleted file mode 100644 index 34c25a9..0000000 --- a/Gtfsrt2LC.js +++ /dev/null @@ -1,4 +0,0 @@ -module.exports = { - GtfsIndex: require('./lib/GtfsIndex.js'), - Gtfsrt2LC: require('./lib/Gtfsrt2LC'), -}; diff --git a/bin/gtfsrt2json.js b/bin/gtfsrt2json.js index 1fce163..5651dfc 100755 --- a/bin/gtfsrt2json.js +++ b/bin/gtfsrt2json.js @@ -1,7 +1,7 @@ #!/usr/bin/env node -const Gtfsrt2LC = require('../lib/Gtfsrt2LC'); -var program = require('commander'); +import { Gtfsrt2LC } from '../lib/Gtfsrt2LC.js'; +import { program } from 'commander'; console.error("GTFS-RT to JSON converter use --help to discover how to use it"); @@ -10,16 +10,16 @@ program .option('-H --headers ', 'Extra HTTP headers for requesting the gtfs files. E.g., {\\"some-header\\":\\"some-API-Key\\"}') .parse(process.argv); -if (!program.realTime) { +if (!program.opts().realTime) { console.error('Please provide a url or a path to a GTFS-RT feed'); process.exit(); } // Set HTTP custom headers, e.g., API keys var headers = {}; -if (program.headers) { +if (program.opts().headers) { try { - headers = JSON.parse(program.headers); + headers = JSON.parse(program.opts().headers); } catch (err) { console.error('Please provide a valid JSON string for the extra HTTP headers'); process.exit(); @@ -27,7 +27,7 @@ if (program.headers) { } async function parse() { - let gtfsrt2lc = new Gtfsrt2LC({ path: program.realTime, headers: headers }); + let gtfsrt2lc = new Gtfsrt2LC({ path: program.opts().realTime, headers: headers }); console.log(JSON.stringify(await gtfsrt2lc.parse2Json())); } diff --git a/bin/gtfsrt2lc.js b/bin/gtfsrt2lc.js index b9bf085..42f3233 100755 --- a/bin/gtfsrt2lc.js +++ b/bin/gtfsrt2lc.js @@ -1,10 +1,10 @@ #!/usr/bin/env node -const fs = require('fs'); -const GtfsIndex = require('../lib/GtfsIndex'); -const Gtfsrt2LC = require('../lib/Gtfsrt2LC'); -const { Level } = require('level'); -const program = require('commander'); +import fs from 'fs'; +import { GtfsIndex } from '../lib/GtfsIndex.js'; +import { Gtfsrt2LC } from '../lib/Gtfsrt2LC.js'; +import { Level } from 'level'; +import { program } from 'commander'; program .option('-r --real-time ', 'URL/path to gtfs-rt feed') @@ -18,27 +18,27 @@ program .option('-h --history ', 'Path to historic Connection LevelStore for differential updates') .parse(process.argv); -if (!program.realTime) { +if (!program.opts().realTime) { console.error('Please provide a url or a path to a GTFS-RT feed'); console.error("GTFS-RT to linked connections converter use --help to discover how to use it"); process.exit(); } -if (!program.static) { +if (!program.opts().static) { console.error('Please provide a url or a path to a GTFS feed'); console.error("GTFS-RT to linked connections converter use --help to discover how to use it"); process.exit(); } -if (!program.store) { - program.store = 'MemStore'; +if (!program.opts().store) { + program.opts().store = 'MemStore'; } // Load URIs template let template = null; try { - if (program.urisTemplate) { - template = JSON.parse(fs.readFileSync(program.urisTemplate, 'utf8')); + if (program.opts().urisTemplate) { + template = JSON.parse(fs.readFileSync(program.opts().urisTemplate, 'utf8')); } } catch (err) { console.error('Please provide a valid path to a template file'); @@ -46,12 +46,12 @@ try { process.exit(); } // Get resulting data format -const format = program.format || 'json'; +const format = program.opts().format || 'json'; // Set HTTP custom headers, e.g., API keys let headers = {}; -if (program.headers) { +if (program.opts().headers) { try { - headers = JSON.parse(program.headers); + headers = JSON.parse(program.opts().headers); } catch (err) { console.error(err); console.error('Please provide a valid JSON string for the extra HTTP headers'); @@ -62,13 +62,13 @@ if (program.headers) { // Load historic connections store (if any) let historyDB = null; -if(program.history) { - historyDB = new Level(program.history, { valueEncoding: 'json' }); +if(program.opts().history) { + historyDB = new Level(program.opts().history, { valueEncoding: 'json' }); } let t0 = new Date(); -const gtfsrt2lc = new Gtfsrt2LC({ path: program.realTime, uris: template, headers: headers }); -const gtfsIndexer = new GtfsIndex({ path: program.static, headers: headers }); +const gtfsrt2lc = new Gtfsrt2LC({ path: program.opts().realTime, uris: template, headers: headers }); +const gtfsIndexer = new GtfsIndex({ path: program.opts().static, headers: headers }); async function processUpdate(store, grep, deduce) { console.error("Converting the GTFS-RT feed to Linked Connections"); @@ -99,4 +99,4 @@ async function processUpdate(store, grep, deduce) { } } -processUpdate(program.store, program.grep, program.deduce); \ No newline at end of file +processUpdate(program.opts().store, program.opts().grep, program.opts().deduce); \ No newline at end of file diff --git a/index.js b/index.js new file mode 100644 index 0000000..5dc147c --- /dev/null +++ b/index.js @@ -0,0 +1,4 @@ +import { GtfsIndex } from './lib/GtfsIndex.js'; +import { Gtfsrt2LC } from './lib/Gtfsrt2LC.js'; + +export default { GtfsIndex, Gtfsrt2LC }; diff --git a/lib/Connections2JSONLD.js b/lib/Connections2JSONLD.js index 389919c..02a4a17 100644 --- a/lib/Connections2JSONLD.js +++ b/lib/Connections2JSONLD.js @@ -1,6 +1,6 @@ import { Transform } from 'stream'; import utpl from 'uri-templates'; -import Utils from './Utils'; +import Utils from './Utils.js'; export class Connections2JSONLD extends Transform { constructor(streamContext, templates) { diff --git a/lib/Connections2Triples.js b/lib/Connections2Triples.js index 009f2a8..c9cbd6a 100644 --- a/lib/Connections2Triples.js +++ b/lib/Connections2Triples.js @@ -1,6 +1,6 @@ import { Transform } from 'stream'; import utpl from 'uri-templates'; -import Utils from './Utils'; +import Utils from './Utils.js'; import { DataFactory } from "rdf-data-factory"; const df = new DataFactory(); diff --git a/lib/GtfsIndex.js b/lib/GtfsIndex.js index c37ed6e..a310d04 100644 --- a/lib/GtfsIndex.js +++ b/lib/GtfsIndex.js @@ -6,7 +6,7 @@ import { parse as parseCsv } from 'fast-csv'; import { deleteAsync as del } from 'del'; import childProcess from 'child_process'; import { Level } from 'level'; -import Utils from './Utils'; +import Utils from './Utils.js'; const exec = util.promisify(childProcess.exec); diff --git a/lib/Gtfsrt2LC.js b/lib/Gtfsrt2LC.js index 59c5c59..36aaac3 100644 --- a/lib/Gtfsrt2LC.js +++ b/lib/Gtfsrt2LC.js @@ -8,9 +8,9 @@ import gtfsrtBindings from 'gtfs-realtime-bindings'; import JSONStream from 'JSONStream'; import { StreamWriter } from 'n3'; import { format, addHours, addMinutes, addSeconds, addDays } from 'date-fns'; -import { Connections2JSONLD } from './Connections2JSONLD'; -import { Connections2CSV } from './Connections2CSV'; -import { Connections2Triples } from './Connections2Triples'; +import { Connections2JSONLD } from './Connections2JSONLD.js'; +import { Connections2CSV } from './Connections2CSV.js'; +import { Connections2Triples } from './Connections2Triples.js'; const readFile = util.promisify(fs.readFile); const days = ['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday']; diff --git a/package-lock.json b/package-lock.json index 8f2e922..533fa26 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "gtfsrt2lc", - "version": "2.2.0", + "version": "2.2.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "gtfsrt2lc", - "version": "2.2.0", + "version": "2.2.1", "license": "MIT", "dependencies": { "adm-zip": "^0.5.16", diff --git a/package.json b/package.json index 8af8fc1..db3a59c 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,8 @@ { "name": "gtfsrt2lc", - "version": "2.2.0", + "version": "2.2.1", "description": "Converts the GTFS-RT to Linked Connections", - "main": "./Gtfsrt2LC.js", + "main": "./index.js", "type": "module", "bin": { "gtfsrt2lc": "bin/gtfsrt2lc.js",