From 5ef1497cd32fd809c7db52422c9ab69733f2216b Mon Sep 17 00:00:00 2001 From: Michael Tsang Date: Fri, 13 Sep 2024 15:02:24 +0100 Subject: [PATCH 1/2] fix filename --- src/cli/OutputGTFSCommand.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cli/OutputGTFSCommand.ts b/src/cli/OutputGTFSCommand.ts index 140f036b..500cff33 100644 --- a/src/cli/OutputGTFSCommand.ts +++ b/src/cli/OutputGTFSCommand.ts @@ -68,7 +68,7 @@ export class OutputGTFSCommand implements CLICommand { */ private async copy(results: object[] | Promise, filename: string): Promise { const rows = await results; - const output = this.output.open(`${this.baseDir}/filename`); + const output = this.output.open(`${this.baseDir}/${filename}`); console.log("Writing " + filename); rows.forEach(row => output.write(row)); From 2d269fc3500e6964abe663f7adbc0e777ac85204 Mon Sep 17 00:00:00 2001 From: Michael Tsang Date: Thu, 26 Sep 2024 12:36:32 +0100 Subject: [PATCH 2/2] fix errors when specifying zip path with spaces --- src/cli/CLICommand.ts | 13 +++++++++++++ src/cli/OutputGTFSZipCommand.ts | 8 ++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/cli/CLICommand.ts b/src/cli/CLICommand.ts index 3d59e90f..1ee9e5c5 100644 --- a/src/cli/CLICommand.ts +++ b/src/cli/CLICommand.ts @@ -1,3 +1,4 @@ +import * as child_process from 'node:child_process'; export interface CLICommand { @@ -7,3 +8,15 @@ export interface CLICommand { run(argv: string[]): Promise; } + +export function processSpawnResult(result : child_process.SpawnSyncReturns) { + if (result.error !== undefined) { + throw result.error; + } + if (result.signal !== null) { + throw Error(`Child process has been killed by signal ${result.signal}`); + } + if (result.status !== null && result.status !== 0) { + throw Error(`Child process exited with non-zero status ${result.status}`); + } +} diff --git a/src/cli/OutputGTFSZipCommand.ts b/src/cli/OutputGTFSZipCommand.ts index b1acd20a..fad777f9 100644 --- a/src/cli/OutputGTFSZipCommand.ts +++ b/src/cli/OutputGTFSZipCommand.ts @@ -1,10 +1,10 @@ import * as os from 'node:os'; import * as path from 'node:path'; -import {CLICommand} from "./CLICommand"; +import {CLICommand, processSpawnResult} from "./CLICommand"; import {OutputGTFSCommand} from "./OutputGTFSCommand"; import * as fs from "fs"; -import {execSync} from "child_process"; +import {spawnSync} from "child_process"; export class OutputGTFSZipCommand implements CLICommand { @@ -29,8 +29,8 @@ export class OutputGTFSZipCommand implements CLICommand { // when node tells you it's finished writing a file, it's lying. setTimeout(() => { console.log("Writing " + filename); - execSync(`zip -j ${filename} ${argv[3]}/*.txt`); + processSpawnResult(spawnSync('zip', ['-jr', filename, argv[3]])); }, 1000); } -} \ No newline at end of file +}