@@ -137,35 +137,51 @@ export class IosProject extends NSProject {
137
137
return Promise . reject ( 'iOS platform is supported only on OS X.' ) ;
138
138
}
139
139
140
+ let rebuild = ( args . request == "launch" ) ? ( args as ILaunchRequestArgs ) . rebuild : true ;
140
141
// build command to execute
141
142
let command = new CommandBuilder ( )
142
143
. appendParam ( "debug" )
143
144
. appendParam ( this . platform ( ) )
144
145
. appendParamIf ( "--emulator" , args . emulator )
145
146
. appendParamIf ( "--start" , args . request === "attach" )
146
147
. appendParamIf ( "--debug-brk" , args . request === "launch" )
148
+ . appendParamIf ( "--no-rebuild" , ! rebuild )
147
149
. appendParam ( "--no-client" )
148
150
. appendParams ( args . tnsArgs )
149
151
. build ( ) ;
150
152
151
153
let socketPathPrefix = 'socket-file-location: ' ;
152
154
let socketPathPattern : RegExp = new RegExp ( socketPathPrefix + '.*\.sock' ) ;
153
- let readyToConnect : boolean = false ;
155
+
156
+ let isSocketOpened = ( cliOutput : string ) : string => {
157
+ let matches : RegExpMatchArray = cliOutput . match ( socketPathPattern ) ;
158
+ if ( matches && matches . length > 0 ) {
159
+ return matches [ 0 ] . substr ( socketPathPrefix . length ) ;
160
+ }
161
+ return null ;
162
+ } ;
163
+
164
+ let isAppSynced = ( cliOutput : string ) => {
165
+ return cliOutput . indexOf ( 'Successfully synced application' ) > - 1 ;
166
+ } ;
154
167
155
168
return new Promise < string > ( ( resolve , reject ) => {
156
169
// run NativeScript CLI command
157
170
let child : ChildProcess = this . spawnProcess ( command . path , command . args , args . tnsOutput ) ;
158
171
172
+ let appSynced = false ;
173
+ let socketPath : string = null ;
174
+
159
175
child . stdout . on ( 'data' , ( data ) => {
160
- let strData : string = data . toString ( ) ;
161
- this . emit ( 'TNS.outputMessage' , strData , 'log' ) ;
162
- this . writeToTnsOutputFile ( strData ) ;
163
- if ( ! readyToConnect ) {
164
- let matches : RegExpMatchArray = strData . match ( socketPathPattern ) ;
165
- if ( matches && matches . length > 0 ) {
166
- readyToConnect = true ;
167
- resolve ( matches [ 0 ] . substr ( socketPathPrefix . length ) ) ;
168
- }
176
+ let cliOutput : string = data . toString ( ) ;
177
+ this . emit ( 'TNS.outputMessage' , cliOutput , 'log' ) ;
178
+ this . writeToTnsOutputFile ( cliOutput ) ;
179
+
180
+ socketPath = socketPath || isSocketOpened ( cliOutput ) ;
181
+ appSynced = rebuild ? false : ( appSynced || isAppSynced ( cliOutput ) ) ;
182
+
183
+ if ( ( rebuild && socketPath ) || ( ! rebuild && socketPath && appSynced ) ) {
184
+ resolve ( socketPath ) ;
169
185
}
170
186
} ) ;
171
187
@@ -207,11 +223,12 @@ export class AndroidProject extends NSProject {
207
223
return Promise . resolve ( child ) ;
208
224
}
209
225
210
- public debug ( args : IAttachRequestArgs | ILaunchRequestArgs ) : Promise < void > {
211
- if ( args . request === "attach" ) {
226
+ public debug ( params : IAttachRequestArgs | ILaunchRequestArgs ) : Promise < void > {
227
+ if ( params . request === "attach" ) {
212
228
return Promise . resolve < void > ( ) ;
213
229
}
214
- else if ( args . request === "launch" ) {
230
+ else if ( params . request === "launch" ) {
231
+ let args : ILaunchRequestArgs = params as ILaunchRequestArgs ;
215
232
let that = this ;
216
233
let launched = false ;
217
234
@@ -220,6 +237,7 @@ export class AndroidProject extends NSProject {
220
237
. appendParam ( "debug" )
221
238
. appendParam ( this . platform ( ) )
222
239
. appendParamIf ( "--emulator" , args . emulator )
240
+ . appendParamIf ( "--no-rebuild" , args . rebuild !== true )
223
241
. appendParam ( "--debug-brk" )
224
242
. appendParam ( "--no-client" )
225
243
. appendParams ( args . tnsArgs )
@@ -233,13 +251,14 @@ export class AndroidProject extends NSProject {
233
251
let strData : string = data . toString ( ) ;
234
252
that . emit ( 'TNS.outputMessage' , data . toString ( ) , 'log' ) ;
235
253
that . writeToTnsOutputFile ( strData ) ;
236
- if ( ! launched && args . request === "launch" && strData . indexOf ( '# NativeScript Debugger started #' ) > - 1 ) {
237
- launched = true ;
238
-
239
- //wait a little before trying to connect, this gives a changes for adb to be able to connect to the debug socket
240
- setTimeout ( ( ) => {
241
- resolve ( ) ;
242
- } , 500 ) ;
254
+ if ( ! launched ) {
255
+ if ( args . request === "launch" && ( ( strData . indexOf ( '# NativeScript Debugger started #' ) > - 1 ) || strData . indexOf ( 'Successfully synced application' ) > - 1 ) ) {
256
+ launched = true ;
257
+ //wait a little before trying to connect, this gives a changes for adb to be able to connect to the debug socket
258
+ setTimeout ( ( ) => {
259
+ resolve ( ) ;
260
+ } , 500 ) ;
261
+ }
243
262
}
244
263
} ) ;
245
264
@@ -249,7 +268,14 @@ export class AndroidProject extends NSProject {
249
268
} ) ;
250
269
251
270
child . on ( 'close' , function ( code ) {
252
- reject ( "The debug process exited unexpectedly code:" + code ) ;
271
+ if ( ! args . rebuild ) {
272
+ setTimeout ( ( ) => {
273
+ reject ( "The debug process exited unexpectedly code:" + code ) ;
274
+ } , 3000 ) ;
275
+ }
276
+ else {
277
+ reject ( "The debug process exited unexpectedly code:" + code ) ;
278
+ }
253
279
} ) ;
254
280
} ) ;
255
281
}
0 commit comments