Skip to content

Commit 412f0aa

Browse files
Return the child process of print device log
If someone wants to use the child process which is used to get the device log we need to return it when the printDeviceLog method is called.
1 parent a84ad2c commit 412f0aa

6 files changed

+49
-46
lines changed

lib/declarations.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ interface ISimulator extends INameGetter {
5555
uninstallApplication(deviceId: string, appIdentifier: string): IFuture<void>;
5656
startApplication(deviceId: string, appIdentifier: string): IFuture<string>;
5757
stopApplication(deviceId: string, appIdentifier: string): IFuture<string>;
58-
printDeviceLog(deviceId: string, launchResult?: string): void;
58+
printDeviceLog(deviceId: string, launchResult?: string): any;
5959
startSimulator(): IFuture<void>;
6060
}
6161

@@ -85,4 +85,4 @@ interface IXcodeVersionData {
8585
major: string;
8686
minor: string;
8787
build: string;
88-
}
88+
}

lib/iphone-simulator-common.ts

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,24 @@
22
"use strict";
33

44
import childProcess = require("./child-process");
5+
import xcode = require("./xcode");
56
import Future = require("fibers/future");
67
import * as fs from "fs";
78
import * as path from "path";
89
import * as os from "os";
9-
import xcode = require("./xcode");
1010
import * as _ from "lodash";
1111

1212
let bplistParser = require("bplist-parser");
1313
let plist = require("plist");
1414
let osenv = require("osenv");
1515
let isDeviceLogOperationStarted = false;
1616
let pid: string;
17+
let deviceLogChildProcess: any;
1718

1819
export function getInstalledApplications(deviceId: string): IFuture<IApplication[]> {
1920
return (() => {
2021
let rootApplicationsPath = path.join(osenv.home(), `/Library/Developer/CoreSimulator/Devices/${deviceId}/data/Containers/Bundle/Application`);
21-
if(!fs.existsSync(rootApplicationsPath)) {
22+
if (!fs.existsSync(rootApplicationsPath)) {
2223
rootApplicationsPath = path.join(osenv.home(), `/Library/Developer/CoreSimulator/Devices/${deviceId}/data/Applications`);
2324
}
2425
let applicationGuids = fs.readdirSync(rootApplicationsPath);
@@ -41,18 +42,18 @@ export function getInstalledApplications(deviceId: string): IFuture<IApplication
4142
}).future<IApplication[]>()();
4243
}
4344

44-
export function printDeviceLog(deviceId: string, launchResult?: string): void {
45-
if(launchResult) {
45+
export function printDeviceLog(deviceId: string, launchResult?: string): any {
46+
if (launchResult) {
4647
pid = launchResult.split(":")[1].trim();
4748
}
4849

49-
if(!isDeviceLogOperationStarted) {
50+
if (!isDeviceLogOperationStarted) {
5051
let logFilePath = path.join(osenv.home(), "Library", "Logs", "CoreSimulator", deviceId, "system.log");
51-
let childProcess = require("child_process").spawn("tail", ['-f', '-n', '1', logFilePath]);
52-
if (childProcess.stdout) {
53-
childProcess.stdout.on("data", (data: NodeBuffer) => {
52+
deviceLogChildProcess = require("child_process").spawn("tail", ['-f', '-n', '1', logFilePath]);
53+
if (deviceLogChildProcess.stdout) {
54+
deviceLogChildProcess.stdout.on("data", (data: NodeBuffer) => {
5455
let dataAsString = data.toString();
55-
if(pid) {
56+
if (pid) {
5657
if (dataAsString.indexOf(`[${pid}]`) > -1) {
5758
process.stdout.write(dataAsString);
5859
}
@@ -62,10 +63,10 @@ export function printDeviceLog(deviceId: string, launchResult?: string): void {
6263
});
6364
}
6465

65-
if (childProcess.stderr) {
66-
childProcess.stderr.on("data", (data: string) => {
66+
if (deviceLogChildProcess.stderr) {
67+
deviceLogChildProcess.stderr.on("data", (data: string) => {
6768
let dataAsString = data.toString();
68-
if(pid) {
69+
if (pid) {
6970
if (dataAsString.indexOf(`[${pid}]`) > -1) {
7071
process.stdout.write(dataAsString);
7172
}
@@ -78,6 +79,8 @@ export function printDeviceLog(deviceId: string, launchResult?: string): void {
7879

7980
isDeviceLogOperationStarted = true;
8081
}
82+
83+
return deviceLogChildProcess;
8184
}
8285

8386
export function startSimulator(deviceId: string): IFuture<void> {
@@ -91,7 +94,7 @@ export function startSimulator(deviceId: string): IFuture<void> {
9194
function parseFile(plistFilePath: string): IFuture<any> {
9295
let future = new Future<any>();
9396
bplistParser.parseFile(plistFilePath, (err: Error, obj: any) => {
94-
if(err) {
97+
if (err) {
9598
future.throw(err);
9699
} else {
97100
future.return(obj);
@@ -112,4 +115,4 @@ function getBundleIdentifier(plistFilePath: string): IFuture<string> {
112115

113116
return plistData && plistData.CFBundleIdentifier;
114117
}).future<string>()();
115-
}
118+
}

lib/iphone-simulator-xcode-5.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export class XCode5Simulator extends iPhoneSimulatorBaseLib.IPhoneInteropSimulat
5252
}).future<ISdk[]>()();
5353
}
5454

55-
public setSimulatedDevice(config:any): void {
55+
public setSimulatedDevice(config: any): void {
5656
config("setSimulatedDeviceInfoName", $(this.deviceIdentifier));
5757
}
5858

@@ -84,7 +84,7 @@ export class XCode5Simulator extends iPhoneSimulatorBaseLib.IPhoneInteropSimulat
8484
return Future.fromResult("");
8585
}
8686

87-
public printDeviceLog(deviceId: string): void { }
87+
public printDeviceLog(deviceId: string): any { }
8888

8989
public startSimulator(): IFuture<void> {
9090
return Future.fromResult();
@@ -93,4 +93,4 @@ export class XCode5Simulator extends iPhoneSimulatorBaseLib.IPhoneInteropSimulat
9393
private get deviceIdentifier(): string {
9494
return XCode5Simulator.allowedDeviceIdentifiers[this.getSimulatorName()];
9595
}
96-
}
96+
}

lib/iphone-simulator-xcode-6.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ export class XCode6Simulator extends iPhoneSimulatorBaseLib.IPhoneInteropSimulat
8484
}
8585
}
8686

87-
public printDeviceLog(deviceId: string, launchResult?: string): void {
88-
common.printDeviceLog(deviceId, launchResult);
87+
public printDeviceLog(deviceId: string, launchResult?: string): any {
88+
return common.printDeviceLog(deviceId, launchResult);
8989
}
9090

9191
public startSimulator(): IFuture<void> {
@@ -172,4 +172,4 @@ export class XCode6Simulator extends iPhoneSimulatorBaseLib.IPhoneInteropSimulat
172172
private buildFullDeviceIdentifier(deviceIdentifier: string): string {
173173
return util.format("%s.%s", XCode6Simulator.DEVICE_IDENTIFIER_PREFIX, deviceIdentifier);
174174
}
175-
}
175+
}

lib/iphone-simulator-xcode-7.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export class XCode7Simulator extends IPhoneSimulatorNameGetter implements ISimul
4646
return (() => {
4747
let device = this.getDeviceToRun().wait();
4848
let currentBootedDevice = _.find(this.getDevices().wait(), device => this.isDeviceBooted(device));
49-
if(currentBootedDevice && (currentBootedDevice.name.toLowerCase() !== device.name.toLowerCase() || currentBootedDevice.runtimeVersion !== device.runtimeVersion)) {
49+
if (currentBootedDevice && (currentBootedDevice.name.toLowerCase() !== device.name.toLowerCase() || currentBootedDevice.runtimeVersion !== device.runtimeVersion)) {
5050
this.killSimulator().wait();
5151
}
5252

@@ -86,7 +86,7 @@ export class XCode7Simulator extends IPhoneSimulatorNameGetter implements ISimul
8686
}
8787

8888
public uninstallApplication(deviceId: string, appIdentifier: string): IFuture<void> {
89-
return this.simctl.uninstall(deviceId, appIdentifier, {skipError: true});
89+
return this.simctl.uninstall(deviceId, appIdentifier, { skipError: true });
9090
}
9191

9292
public startApplication(deviceId: string, appIdentifier: string): IFuture<string> {
@@ -95,13 +95,13 @@ export class XCode7Simulator extends IPhoneSimulatorNameGetter implements ISimul
9595

9696
public stopApplication(deviceId: string, cfBundleExecutable: string): IFuture<string> {
9797
try {
98-
return childProcess.exec(`killall ${cfBundleExecutable}`, {skipError: true});
99-
} catch(e) {
98+
return childProcess.exec(`killall ${cfBundleExecutable}`, { skipError: true });
99+
} catch (e) {
100100
}
101101
}
102102

103-
public printDeviceLog(deviceId: string, launchResult?: string): void {
104-
common.printDeviceLog(deviceId, launchResult);
103+
public printDeviceLog(deviceId: string, launchResult?: string): any {
104+
return common.printDeviceLog(deviceId, launchResult);
105105
}
106106

107107
private getDeviceToRun(): IFuture<IDevice> {
@@ -110,28 +110,28 @@ export class XCode7Simulator extends IPhoneSimulatorNameGetter implements ISimul
110110
sdkVersion = options.sdkVersion || options.sdk;
111111

112112
let result = _.find(devices, (device: IDevice) => {
113-
if(sdkVersion && !options.device) {
113+
if (sdkVersion && !options.device) {
114114
return device.runtimeVersion === sdkVersion;
115115
}
116116

117-
if(options.device && !sdkVersion) {
117+
if (options.device && !sdkVersion) {
118118
return device.name === options.device;
119119
}
120120

121-
if(options.device && sdkVersion) {
121+
if (options.device && sdkVersion) {
122122
return device.runtimeVersion === sdkVersion && device.name === options.device;
123123
}
124124

125-
if(!sdkVersion && !options.device) {
125+
if (!sdkVersion && !options.device) {
126126
return this.isDeviceBooted(device);
127127
}
128128
});
129129

130-
if(!result) {
130+
if (!result) {
131131
result = _.find(devices, (device: IDevice) => device.name === this.defaultDeviceIdentifier);
132132
}
133133

134-
if(!result) {
134+
if (!result) {
135135
let sortedDevices = _.sortBy(devices, (device) => device.runtimeVersion);
136136
result = _.last(sortedDevices);
137137
}

lib/iphone-simulator-xcode-8.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export class XCode8Simulator extends IPhoneSimulatorNameGetter implements ISimul
4646
return (() => {
4747
let device = this.getDeviceToRun().wait();
4848
let currentBootedDevice = _.find(this.getDevices().wait(), device => this.isDeviceBooted(device));
49-
if(currentBootedDevice && (currentBootedDevice.name.toLowerCase() !== device.name.toLowerCase() || currentBootedDevice.runtimeVersion !== device.runtimeVersion)) {
49+
if (currentBootedDevice && (currentBootedDevice.name.toLowerCase() !== device.name.toLowerCase() || currentBootedDevice.runtimeVersion !== device.runtimeVersion)) {
5050
this.killSimulator().wait();
5151
}
5252

@@ -86,7 +86,7 @@ export class XCode8Simulator extends IPhoneSimulatorNameGetter implements ISimul
8686
}
8787

8888
public uninstallApplication(deviceId: string, appIdentifier: string): IFuture<void> {
89-
return this.simctl.uninstall(deviceId, appIdentifier, {skipError: true});
89+
return this.simctl.uninstall(deviceId, appIdentifier, { skipError: true });
9090
}
9191

9292
public startApplication(deviceId: string, appIdentifier: string): IFuture<string> {
@@ -95,13 +95,13 @@ export class XCode8Simulator extends IPhoneSimulatorNameGetter implements ISimul
9595

9696
public stopApplication(deviceId: string, cfBundleExecutable: string): IFuture<string> {
9797
try {
98-
return childProcess.exec(`killall ${cfBundleExecutable}`, {skipError: true});
99-
} catch(e) {
98+
return childProcess.exec(`killall ${cfBundleExecutable}`, { skipError: true });
99+
} catch (e) {
100100
}
101101
}
102102

103-
public printDeviceLog(deviceId: string, launchResult?: string): void {
104-
common.printDeviceLog(deviceId, launchResult);
103+
public printDeviceLog(deviceId: string, launchResult?: string): any {
104+
return common.printDeviceLog(deviceId, launchResult);
105105
}
106106

107107
private getDeviceToRun(): IFuture<IDevice> {
@@ -110,28 +110,28 @@ export class XCode8Simulator extends IPhoneSimulatorNameGetter implements ISimul
110110
sdkVersion = options.sdkVersion || options.sdk;
111111

112112
let result = _.find(devices, (device: IDevice) => {
113-
if(sdkVersion && !options.device) {
113+
if (sdkVersion && !options.device) {
114114
return device.runtimeVersion === sdkVersion;
115115
}
116116

117-
if(options.device && !sdkVersion) {
117+
if (options.device && !sdkVersion) {
118118
return device.name === options.device;
119119
}
120120

121-
if(options.device && sdkVersion) {
121+
if (options.device && sdkVersion) {
122122
return device.runtimeVersion === sdkVersion && device.name === options.device;
123123
}
124124

125-
if(!sdkVersion && !options.device) {
125+
if (!sdkVersion && !options.device) {
126126
return this.isDeviceBooted(device);
127127
}
128128
});
129129

130-
if(!result) {
130+
if (!result) {
131131
result = _.find(devices, (device: IDevice) => device.name === this.defaultDeviceIdentifier);
132132
}
133133

134-
if(!result) {
134+
if (!result) {
135135
let sortedDevices = _.sortBy(devices, (device) => device.runtimeVersion);
136136
result = _.last(sortedDevices);
137137
}

0 commit comments

Comments
 (0)