Skip to content

Commit

Permalink
fix filename (#100)
Browse files Browse the repository at this point in the history
* fix filename

* fix errors when specifying zip path with spaces
  • Loading branch information
miklcct authored Sep 26, 2024
1 parent d55bbad commit d1dd32b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
13 changes: 13 additions & 0 deletions src/cli/CLICommand.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as child_process from 'node:child_process';

export interface CLICommand {

Expand All @@ -7,3 +8,15 @@ export interface CLICommand {
run(argv: string[]): Promise<any>;

}

export function processSpawnResult(result : child_process.SpawnSyncReturns<Buffer>) {
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}`);
}
}
2 changes: 1 addition & 1 deletion src/cli/OutputGTFSCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export class OutputGTFSCommand implements CLICommand {
*/
private async copy(results: object[] | Promise<object[]>, filename: string): Promise<void> {
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));
Expand Down
8 changes: 4 additions & 4 deletions src/cli/OutputGTFSZipCommand.ts
Original file line number Diff line number Diff line change
@@ -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 {

Expand All @@ -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);
}

}
}

0 comments on commit d1dd32b

Please sign in to comment.