@@ -34,14 +34,14 @@ export class iPhoneSimulator implements IiPhoneSimulator {
34
34
errors . fail ( "Path does not exist " , appPath ) ;
35
35
}
36
36
37
- return this . execute ( this . launch , { canRunMainLoop : true , appPath : appPath } ) ;
37
+ return this . execute ( this . launch , { canRunMainLoop : true , appPath : appPath } ) ;
38
38
}
39
39
40
40
public printDeviceTypes ( ) : IFuture < void > {
41
41
var action = ( ) => {
42
42
var simulator = this . createSimulator ( ) ;
43
43
_ . each ( simulator . deviceIdentifiersInfo , ( identifier : any ) => console . log ( identifier ) ) ;
44
- }
44
+ } ;
45
45
46
46
return this . execute ( action , { canRunMainLoop : false } ) ;
47
47
}
@@ -71,27 +71,35 @@ export class iPhoneSimulator implements IiPhoneSimulator {
71
71
}
72
72
73
73
private execute ( action : ( appPath ?: string ) => any , opts : IExecuteOptions ) : IFuture < void > {
74
- return ( ( ) => {
75
- $ . importFramework ( iPhoneSimulator . FOUNDATION_FRAMEWORK_NAME ) ;
76
- $ . importFramework ( iPhoneSimulator . APPKIT_FRAMEWORK_NAME ) ;
74
+ $ . importFramework ( iPhoneSimulator . FOUNDATION_FRAMEWORK_NAME ) ;
75
+ $ . importFramework ( iPhoneSimulator . APPKIT_FRAMEWORK_NAME ) ;
77
76
78
- var pool = $ . NSAutoreleasePool ( "alloc" ) ( "init" ) ;
79
-
80
- var developerDirectoryPath = this . findDeveloperDirectory ( ) . wait ( ) ;
81
- if ( ! developerDirectoryPath ) {
82
- errors . fail ( "Unable to find developer directory" ) ;
83
- }
77
+ var pool = $ . NSAutoreleasePool ( "alloc" ) ( "init" ) ;
84
78
85
- this . loadFrameworks ( developerDirectoryPath ) ;
86
-
87
- action . apply ( this , [ opts . appPath ] ) ;
88
-
89
- if ( opts . canRunMainLoop ) {
90
- $ . NSRunLoop ( "mainRunLoop" ) ( "run" ) ;
91
- }
79
+ var developerDirectoryPath = this . findDeveloperDirectory ( ) . wait ( ) ;
80
+ if ( ! developerDirectoryPath ) {
81
+ errors . fail ( "Unable to find developer directory" ) ;
82
+ }
92
83
93
- pool ( "release" ) ;
94
- } ) . future < void > ( ) ( ) ;
84
+ this . loadFrameworks ( developerDirectoryPath ) ;
85
+
86
+ action . apply ( this , [ opts . appPath ] ) ;
87
+
88
+ var future = new Future < void > ( ) ;
89
+ if ( opts . canRunMainLoop ) {
90
+ // Keeps the Node loop running
91
+ ( function runLoop ( ) {
92
+ if ( $ . CFRunLoopRunInMode ( $ . kCFRunLoopDefaultMode , 0.1 , false ) ) {
93
+ setTimeout ( runLoop , 0 ) ;
94
+ } else {
95
+ pool ( "release" ) ;
96
+ future . return ( ) ;
97
+ }
98
+ } ( ) ) ;
99
+ } else {
100
+ future . return ( ) ;
101
+ }
102
+ return future ;
95
103
}
96
104
97
105
private launch ( appPath : string ) : void {
@@ -124,12 +132,18 @@ export class iPhoneSimulator implements IiPhoneSimulator {
124
132
}
125
133
simulator . setSimulatedDevice ( config ) ;
126
134
127
- if ( options . stderr ) {
128
- config ( "setSimulatedApplicationStdErrPath" , $ ( options . stderr ) ) ;
129
- }
130
-
131
- if ( options . stdout ) {
132
- config ( "setSimulatedApplicationStdOutPath" , $ ( options . stdout ) ) ;
135
+ if ( options . logging ) {
136
+ var logPath = this . createLogPipe ( appPath ) . wait ( ) ;
137
+ fs . createReadStream ( logPath , { encoding : "utf8" } ) . pipe ( process . stdout ) ;
138
+ config ( "setSimulatedApplicationStdErrPath" , $ ( logPath ) ) ;
139
+ config ( "setSimulatedApplicationStdOutPath" , $ ( logPath ) ) ;
140
+ } else {
141
+ if ( options . stderr ) {
142
+ config ( "setSimulatedApplicationStdErrPath" , $ ( options . stderr ) ) ;
143
+ }
144
+ if ( options . stdout ) {
145
+ config ( "setSimulatedApplicationStdOutPath" , $ ( options . stdout ) ) ;
146
+ }
133
147
}
134
148
135
149
config ( "setLocalizedClientName" , $ ( "ios-sim-portable" ) ) ;
@@ -180,7 +194,7 @@ export class iPhoneSimulator implements IiPhoneSimulator {
180
194
}
181
195
182
196
private loadFramework ( frameworkPath : string ) {
183
- var bundle = $ . NSBundle ( "bundleWithPath" , $ ( frameworkPath ) ) ;
197
+ var bundle = $ . NSBundle ( "bundleWithPath" , $ ( frameworkPath ) ) ;
184
198
if ( ! bundle ( "load" ) ) {
185
199
errors . fail ( "Unable to load " , frameworkPath ) ;
186
200
}
@@ -244,6 +258,22 @@ export class iPhoneSimulator implements IiPhoneSimulator {
244
258
245
259
return simulator ;
246
260
}
261
+
262
+ private createLogPipe ( appPath : string ) : IFuture < string > {
263
+ var future = new Future < string > ( ) ;
264
+ var logPath = path . join ( path . dirname ( appPath ) , "." + path . basename ( appPath , ".app" ) + ".log" ) ;
265
+
266
+ var command = util . format ( "rm -f %s && mkfifo %s" , logPath , logPath ) ;
267
+ child_process . exec ( command , ( error : Error , stdout : NodeBuffer , stderr : NodeBuffer ) => {
268
+ if ( error ) {
269
+ future . throw ( error ) ;
270
+ } else {
271
+ future . return ( logPath ) ;
272
+ }
273
+ } ) ;
274
+
275
+ return future ;
276
+ }
247
277
}
248
278
249
279
class Sdk implements ISdk {
0 commit comments