@@ -141,41 +141,56 @@ export class WebKitDebugAdapter implements DebugProtocol.IDebugAdapter {
141141 this . _request = new DebugRequest ( args , Services . cli ( ) ) ;
142142 Services . extensionClient ( ) . analyticsLaunchDebugger ( { request : this . _request . isSync ? "sync" : args . request , platform : args . platform } ) ;
143143
144- // Run CLI Command
145- let cliCommand : DebugResult ;
146- if ( this . _request . isLaunch ) {
147- cliCommand = this . _request . project . debug ( { stopOnEntry : this . _request . launchArgs . stopOnEntry } , this . _request . args . tnsArgs ) ;
148- }
149- else if ( this . _request . isSync ) {
150- cliCommand = this . _request . project . debugWithSync ( { stopOnEntry : this . _request . launchArgs . stopOnEntry , syncAllFiles : this . _request . launchArgs . syncAllFiles } , this . _request . args . tnsArgs ) ;
151- }
152- else if ( this . _request . isAttach ) {
153- cliCommand = this . _request . project . attach ( this . _request . args . tnsArgs ) ;
144+ // FIXME: Workaround for https://github.com/NativeScript/nativescript-cli/issues/2292
145+ let cliBuildCommand = Promise . resolve ( ) ;
146+ if ( this . _request . isSync && ! fs . existsSync ( this . _request . project . platformBuildPath ( ) ) ) {
147+ cliBuildCommand = new Promise ( ( resolve , reject ) => {
148+ let cliBuildProcess = this . _request . project . build ( [ ] ) ;
149+ cliBuildProcess . stdout . on ( 'data' , data => { Services . logger ( ) . log ( data . toString ( ) , Tags . FrontendMessage ) ; } ) ;
150+ cliBuildProcess . stderr . on ( 'data' , data => { Services . logger ( ) . error ( data . toString ( ) , Tags . FrontendMessage ) ; } ) ;
151+ cliBuildProcess . on ( 'close' , ( code ) => {
152+ code ? reject ( `The build command exited with code: ${ code } ` ) : resolve ( ) ;
153+ } ) ;
154+ } ) ;
154155 }
155156
156- if ( cliCommand . tnsProcess ) {
157- cliCommand . tnsProcess . stdout . on ( 'data' , data => { Services . logger ( ) . log ( data . toString ( ) , Tags . FrontendMessage ) ; } ) ;
158- cliCommand . tnsProcess . stderr . on ( 'data' , data => { Services . logger ( ) . error ( data . toString ( ) , Tags . FrontendMessage ) ; } ) ;
159- cliCommand . tnsProcess . on ( 'close' , ( code , signal ) => { Services . logger ( ) . error ( `The tns command finished its execution with code ${ code } .` , Tags . FrontendMessage ) ; } ) ;
160- }
157+ return cliBuildCommand . then ( ( ) => {
158+ // Run CLI Command
159+ let cliCommand : DebugResult ;
160+ if ( this . _request . isLaunch ) {
161+ cliCommand = this . _request . project . debug ( { stopOnEntry : this . _request . launchArgs . stopOnEntry } , this . _request . args . tnsArgs ) ;
162+ }
163+ else if ( this . _request . isSync ) {
164+ cliCommand = this . _request . project . debugWithSync ( { stopOnEntry : this . _request . launchArgs . stopOnEntry , syncAllFiles : this . _request . launchArgs . syncAllFiles } , this . _request . args . tnsArgs ) ;
165+ }
166+ else if ( this . _request . isAttach ) {
167+ cliCommand = this . _request . project . attach ( this . _request . args . tnsArgs ) ;
168+ }
169+
170+ if ( cliCommand . tnsProcess ) {
171+ cliCommand . tnsProcess . stdout . on ( 'data' , data => { Services . logger ( ) . log ( data . toString ( ) , Tags . FrontendMessage ) ; } ) ;
172+ cliCommand . tnsProcess . stderr . on ( 'data' , data => { Services . logger ( ) . error ( data . toString ( ) , Tags . FrontendMessage ) ; } ) ;
173+ cliCommand . tnsProcess . on ( 'close' , ( code , signal ) => { Services . logger ( ) . error ( `The tns command finished its execution with code ${ code } .` , Tags . FrontendMessage ) ; } ) ;
174+ }
161175
162- let promiseResolve = null ;
163- let promise : Promise < void > = new Promise < void > ( ( res , rej ) => { promiseResolve = res ; } ) ;
164- // Attach to the running application
165- cliCommand . tnsOutputEventEmitter . on ( 'readyForConnection' , ( connectionToken : string | number ) => {
166- connectionToken = this . _request . isAndroid ? this . _request . androidProject . getDebugPortSync ( ) : connectionToken ;
167- Services . logger ( ) . log ( `Attaching to application on ${ connectionToken } ` ) ;
168- let connection : INSDebugConnection = this . _request . isAndroid ? new AndroidConnection ( ) : new IosConnection ( ) ;
169- this . setConnection ( connection ) ;
170- let attachPromise = this . _request . isAndroid ? ( < AndroidConnection > connection ) . attach ( < number > connectionToken , 'localhost' ) : ( < IosConnection > connection ) . attach ( < string > connectionToken ) ;
171- attachPromise . then ( ( ) => {
172- // Send InitializedEvent
173- this . fireEvent ( new InitializedEvent ( ) ) ;
174- promiseResolve ( ) ;
176+ let promiseResolve = null ;
177+ let promise : Promise < void > = new Promise < void > ( ( res , rej ) => { promiseResolve = res ; } ) ;
178+ // Attach to the running application
179+ cliCommand . tnsOutputEventEmitter . on ( 'readyForConnection' , ( connectionToken : string | number ) => {
180+ connectionToken = this . _request . isAndroid ? this . _request . androidProject . getDebugPortSync ( ) : connectionToken ;
181+ Services . logger ( ) . log ( `Attaching to application on ${ connectionToken } ` ) ;
182+ let connection : INSDebugConnection = this . _request . isAndroid ? new AndroidConnection ( ) : new IosConnection ( ) ;
183+ this . setConnection ( connection ) ;
184+ let attachPromise = this . _request . isAndroid ? ( < AndroidConnection > connection ) . attach ( < number > connectionToken , 'localhost' ) : ( < IosConnection > connection ) . attach ( < string > connectionToken ) ;
185+ attachPromise . then ( ( ) => {
186+ // Send InitializedEvent
187+ this . fireEvent ( new InitializedEvent ( ) ) ;
188+ promiseResolve ( ) ;
189+ } ) ;
175190 } ) ;
176- } ) ;
177191
178- return promise ;
192+ return promise ;
193+ } ) ;
179194 } ) ;
180195
181196 }
0 commit comments