@@ -137,35 +137,51 @@ export class IosProject extends NSProject {
137137 return Promise . reject ( 'iOS platform is supported only on OS X.' ) ;
138138 }
139139
140+ let rebuild = ( args . request == "launch" ) ? ( args as ILaunchRequestArgs ) . rebuild : true ;
140141 // build command to execute
141142 let command = new CommandBuilder ( )
142143 . appendParam ( "debug" )
143144 . appendParam ( this . platform ( ) )
144145 . appendParamIf ( "--emulator" , args . emulator )
145146 . appendParamIf ( "--start" , args . request === "attach" )
146147 . appendParamIf ( "--debug-brk" , args . request === "launch" )
148+ . appendParamIf ( "--no-rebuild" , ! rebuild )
147149 . appendParam ( "--no-client" )
148150 . appendParams ( args . tnsArgs )
149151 . build ( ) ;
150152
151153 let socketPathPrefix = 'socket-file-location: ' ;
152154 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+ } ;
154167
155168 return new Promise < string > ( ( resolve , reject ) => {
156169 // run NativeScript CLI command
157170 let child : ChildProcess = this . spawnProcess ( command . path , command . args , args . tnsOutput ) ;
158171
172+ let appSynced = false ;
173+ let socketPath : string = null ;
174+
159175 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 ) ;
169185 }
170186 } ) ;
171187
@@ -207,11 +223,12 @@ export class AndroidProject extends NSProject {
207223 return Promise . resolve ( child ) ;
208224 }
209225
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" ) {
212228 return Promise . resolve < void > ( ) ;
213229 }
214- else if ( args . request === "launch" ) {
230+ else if ( params . request === "launch" ) {
231+ let args : ILaunchRequestArgs = params as ILaunchRequestArgs ;
215232 let that = this ;
216233 let launched = false ;
217234
@@ -220,6 +237,7 @@ export class AndroidProject extends NSProject {
220237 . appendParam ( "debug" )
221238 . appendParam ( this . platform ( ) )
222239 . appendParamIf ( "--emulator" , args . emulator )
240+ . appendParamIf ( "--no-rebuild" , args . rebuild !== true )
223241 . appendParam ( "--debug-brk" )
224242 . appendParam ( "--no-client" )
225243 . appendParams ( args . tnsArgs )
@@ -233,13 +251,14 @@ export class AndroidProject extends NSProject {
233251 let strData : string = data . toString ( ) ;
234252 that . emit ( 'TNS.outputMessage' , data . toString ( ) , 'log' ) ;
235253 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+ }
243262 }
244263 } ) ;
245264
@@ -249,7 +268,14 @@ export class AndroidProject extends NSProject {
249268 } ) ;
250269
251270 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+ }
253279 } ) ;
254280 } ) ;
255281 }
0 commit comments