From ea0bea45a31392947293e950193cc1c8f740e3f8 Mon Sep 17 00:00:00 2001 From: Julian Rojas Date: Tue, 5 Jul 2022 23:02:07 +0200 Subject: [PATCH 1/2] Handle missing calendar.txt case --- lib/stores/StoreManager.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/stores/StoreManager.js b/lib/stores/StoreManager.js index d9bf882..a4c0be4 100644 --- a/lib/stores/StoreManager.js +++ b/lib/stores/StoreManager.js @@ -1,8 +1,12 @@ const fs = require('fs'); const csv = require('fast-csv'); +const util = require('util'); +const ChildProcess = require('child_process'); const Store = require('./Store'); const Services = require('../services/calendar'); +const exec = util.promisify(ChildProcess.exec); + module.exports = async function (outPath, storeType, isTest) { // Step 2: Read all the required GTFS files in a streamed-fashion const stops = fs.createReadStream(`${outPath}/stops.txt`, { encoding: 'utf8', objectMode: true }) @@ -28,7 +32,11 @@ module.exports = async function (outPath, storeType, isTest) { .on('error', function (e) { console.error(e); }); - + + // Check if calendar.txt exists, otherwise create a dummy file to prevent stream issue + if(!fs.existsSync(`${outPath}/calendar.txt`)) { + await exec('touch calendar.txt', { cwd: outPath }); + } const services = fs.createReadStream(`${outPath}/calendar.txt`, { encoding: 'utf8', objectMode: true }) .pipe(csv.parse({ objectMode: true, headers: true })) .pipe(new Services(calendarDates, isTest)) From a39e51231ad7f6f3c01fb4ffda8538b13615302c Mon Sep 17 00:00:00 2001 From: Julian Rojas Date: Tue, 5 Jul 2022 23:03:16 +0200 Subject: [PATCH 2/2] 2.0.3 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index e0f83be..0031f03 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "gtfs2lc", - "version": "2.0.2", + "version": "2.0.3", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "gtfs2lc", - "version": "2.0.2", + "version": "2.0.3", "license": "MIT", "dependencies": { "asynciterator": "^2.0.1", diff --git a/package.json b/package.json index 27cae54..172ae76 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gtfs2lc", - "version": "2.0.2", + "version": "2.0.3", "description": "Mapping script from gtfs to (linked) connections", "main": "lib/gtfs2lc.js", "bin": {