1
1
import * as path from "path" ;
2
2
import * as choki from "chokidar" ;
3
- import { parse } from "url" ;
4
3
import { EOL } from "os" ;
5
4
import { EventEmitter } from "events" ;
6
5
import { hook } from "../../common/helpers" ;
7
- import { APP_FOLDER_NAME , PACKAGE_JSON_FILE_NAME , LiveSyncTrackActionNames , USER_INTERACTION_NEEDED_EVENT_NAME , DEBUGGER_ATTACHED_EVENT_NAME } from "../../constants" ;
6
+ import { APP_FOLDER_NAME , PACKAGE_JSON_FILE_NAME , LiveSyncTrackActionNames , USER_INTERACTION_NEEDED_EVENT_NAME , DEBUGGER_ATTACHED_EVENT_NAME , DEBUGGER_DETACHED_EVENT_NAME } from "../../constants" ;
8
7
import { FileExtensions , DeviceTypes } from "../../common/constants" ;
9
8
const deviceDescriptorPrimaryKey = "identifier" ;
10
9
@@ -101,7 +100,7 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
101
100
return currentDescriptors || [ ] ;
102
101
}
103
102
104
- private async refreshApplication ( projectData : IProjectData , liveSyncResultInfo : ILiveSyncResultInfo , debugOpts ?: IDebugOptions , outputPath ?: string ) : Promise < void > {
103
+ private async refreshApplication ( projectData : IProjectData , liveSyncResultInfo : ILiveSyncResultInfo , debugOpts ?: IDebugOptions , outputPath ?: string ) : Promise < void | IDebugInformation > {
105
104
const deviceDescriptor = this . getDeviceDescriptor ( liveSyncResultInfo . deviceAppData . device . deviceInfo . identifier , projectData . projectDir ) ;
106
105
107
106
return deviceDescriptor && deviceDescriptor . debugggingEnabled ?
@@ -138,13 +137,14 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
138
137
this . $logger . info ( `Successfully synced application ${ liveSyncResultInfo . deviceAppData . appIdentifier } on device ${ liveSyncResultInfo . deviceAppData . device . deviceInfo . identifier } .` ) ;
139
138
}
140
139
141
- private async refreshApplicationWithDebug ( projectData : IProjectData , liveSyncResultInfo : ILiveSyncResultInfo , debugOptions : IDebugOptions , outputPath ?: string ) : Promise < void > {
140
+ private async refreshApplicationWithDebug ( projectData : IProjectData , liveSyncResultInfo : ILiveSyncResultInfo , debugOptions : IDebugOptions , outputPath ?: string ) : Promise < IDebugInformation > {
142
141
await this . $platformService . trackProjectType ( projectData ) ;
143
142
144
143
const deviceAppData = liveSyncResultInfo . deviceAppData ;
145
144
146
145
const deviceIdentifier = liveSyncResultInfo . deviceAppData . device . deviceInfo . identifier ;
147
146
await this . $debugService . debugStop ( deviceIdentifier ) ;
147
+ this . emit ( DEBUGGER_DETACHED_EVENT_NAME , { deviceIdentifier } ) ;
148
148
149
149
const applicationId = deviceAppData . appIdentifier ;
150
150
const attachDebuggerOptions : IAttachDebuggerOptions = {
@@ -181,7 +181,7 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
181
181
return this . enableDebuggingCoreWithoutWaitingCurrentAction ( deviceOption , { projectDir : projectData . projectDir } ) ;
182
182
}
183
183
184
- public async attachDebugger ( settings : IAttachDebuggerOptions ) : Promise < void > {
184
+ public async attachDebugger ( settings : IAttachDebuggerOptions ) : Promise < IDebugInformation > {
185
185
// Default values
186
186
if ( settings . debugOptions ) {
187
187
settings . debugOptions . chrome = settings . debugOptions . chrome === undefined ? true : settings . debugOptions . chrome ;
@@ -208,22 +208,19 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
208
208
} ;
209
209
debugData . pathToAppPackage = this . $platformService . lastOutputPath ( settings . platform , buildConfig , projectData , settings . outputPath ) ;
210
210
211
- this . printDebugInformation ( await this . $debugService . debug ( debugData , settings . debugOptions ) ) ;
211
+ return this . printDebugInformation ( await this . $debugService . debug ( debugData , settings . debugOptions ) ) ;
212
212
}
213
213
214
- public printDebugInformation ( information : string ) : void {
215
- if ( ! ! information ) {
216
- const wsQueryParam = parse ( information ) . query . ws ;
217
- const hostPortSplit = wsQueryParam && wsQueryParam . split ( ":" ) ;
218
- this . emit ( DEBUGGER_ATTACHED_EVENT_NAME , {
219
- url : information ,
220
- port : hostPortSplit && hostPortSplit [ 1 ]
221
- } ) ;
222
- this . $logger . info ( `To start debugging, open the following URL in Chrome:${ EOL } ${ information } ${ EOL } ` . cyan ) ;
214
+ public printDebugInformation ( debugInformation : IDebugInformation ) : IDebugInformation {
215
+ if ( ! ! debugInformation . url ) {
216
+ this . emit ( DEBUGGER_ATTACHED_EVENT_NAME , debugInformation ) ;
217
+ this . $logger . info ( `To start debugging, open the following URL in Chrome:${ EOL } ${ debugInformation . url } ${ EOL } ` . cyan ) ;
223
218
}
219
+
220
+ return debugInformation ;
224
221
}
225
222
226
- public enableDebugging ( deviceOpts : IEnableDebuggingDeviceOptions [ ] , debuggingAdditionalOptions : IDebuggingAdditionalOptions ) : Promise < void > [ ] {
223
+ public enableDebugging ( deviceOpts : IEnableDebuggingDeviceOptions [ ] , debuggingAdditionalOptions : IDebuggingAdditionalOptions ) : Promise < IDebugInformation > [ ] {
227
224
return _ . map ( deviceOpts , d => this . enableDebuggingCore ( d , debuggingAdditionalOptions ) ) ;
228
225
}
229
226
@@ -233,7 +230,7 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
233
230
return _ . find ( deviceDescriptors , d => d . identifier === deviceIdentifier ) ;
234
231
}
235
232
236
- private async enableDebuggingCoreWithoutWaitingCurrentAction ( deviceOption : IEnableDebuggingDeviceOptions , debuggingAdditionalOptions : IDebuggingAdditionalOptions ) : Promise < void > {
233
+ private async enableDebuggingCoreWithoutWaitingCurrentAction ( deviceOption : IEnableDebuggingDeviceOptions , debuggingAdditionalOptions : IDebuggingAdditionalOptions ) : Promise < IDebugInformation > {
237
234
const currentDeviceDescriptor = this . getDeviceDescriptor ( deviceOption . deviceIdentifier , debuggingAdditionalOptions . projectDir ) ;
238
235
if ( ! currentDeviceDescriptor ) {
239
236
this . $errors . failWithoutHelp ( `Couldn't enable debugging for ${ deviceOption . deviceIdentifier } ` ) ;
@@ -250,16 +247,19 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
250
247
debugOptions : deviceOption . debugOptions
251
248
} ;
252
249
250
+ let debugInformation : IDebugInformation ;
253
251
try {
254
- await this . attachDebugger ( attachDebuggerOptions ) ;
252
+ debugInformation = await this . attachDebugger ( attachDebuggerOptions ) ;
255
253
} catch ( err ) {
256
254
this . $logger . trace ( "Couldn't attach debugger, will modify options and try again." , err ) ;
257
255
attachDebuggerOptions . debugOptions . start = false ;
258
- await this . attachDebugger ( attachDebuggerOptions ) ;
256
+ debugInformation = await this . attachDebugger ( attachDebuggerOptions ) ;
259
257
}
258
+
259
+ return debugInformation ;
260
260
}
261
261
262
- private async enableDebuggingCore ( deviceOption : IEnableDebuggingDeviceOptions , debuggingAdditionalOptions : IDebuggingAdditionalOptions ) : Promise < void > {
262
+ private async enableDebuggingCore ( deviceOption : IEnableDebuggingDeviceOptions , debuggingAdditionalOptions : IDebuggingAdditionalOptions ) : Promise < IDebugInformation > {
263
263
const liveSyncProcessInfo : ILiveSyncProcessInfo = this . liveSyncProcessesInfo [ debuggingAdditionalOptions . projectDir ] ;
264
264
if ( liveSyncProcessInfo && liveSyncProcessInfo . currentSyncAction ) {
265
265
await liveSyncProcessInfo . currentSyncAction ;
@@ -290,7 +290,8 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
290
290
this . $errors . failWithoutHelp ( `Couldn't disable debugging for ${ deviceOption . deviceIdentifier } . Could not find device.` ) ;
291
291
}
292
292
293
- return this . $debugService . debugStop ( currentDevice . deviceInfo . identifier ) ;
293
+ await this . $debugService . debugStop ( currentDevice . deviceInfo . identifier ) ;
294
+ this . emit ( DEBUGGER_DETACHED_EVENT_NAME , { deviceIdentifier : currentDeviceDescriptor . identifier } ) ;
294
295
}
295
296
296
297
@hook ( "liveSync" )
0 commit comments