Skip to content

Commit a4d7229

Browse files
author
Yosif Yosifov
committed
Add spawnSync wrapper
1 parent d79cbfd commit a4d7229

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

lib/child-process.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,18 @@ export function execSync(command: string, opts?: any): any {
1212
}
1313
}
1414

15+
export function spawnSync(command: string, args: string[], opts?: any): any {
16+
try {
17+
return child_process.spawnSync(command, args, opts);
18+
} catch (err) {
19+
if (opts && opts.skipError) {
20+
return err;
21+
} else {
22+
throw (new Error(`Error ${err.message} while executing ${command}.`));
23+
}
24+
}
25+
}
26+
1527
export function spawn(command: string, args: string[], opts?: any): Promise<string> {
1628
return new Promise<string>((resolve, reject) => {
1729
let capturedOut = "";

lib/simctl.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import childProcess = require("./child-process");
2-
import nodeChildProcess = require("child_process");
32
import errors = require("./errors");
43
import options = require("./options");
54
import * as _ from "lodash";
@@ -118,6 +117,10 @@ export class Simctl implements ISimctl {
118117
}
119118

120119
private simctlExec(command: string, args: string[], opts?: any): any {
121-
return nodeChildProcess.spawnSync("xcrun", ["simctl", command].concat(args), opts).stdout.toString().trim();
120+
let result = childProcess.spawnSync("xcrun", ["simctl", command].concat(args), opts);
121+
if(result && result.stdout) {
122+
return result.stdout.toString().trim();
123+
}
124+
return '';
122125
}
123126
}

0 commit comments

Comments
 (0)