@@ -7,13 +7,10 @@ import { exported } from "../../common/decorators";
7
7
import { hook } from "../../common/helpers" ;
8
8
9
9
const LiveSyncEvents = {
10
- liveSyncStarted : "liveSyncStarted" ,
11
10
liveSyncStopped : "liveSyncStopped" ,
12
- liveSyncError : "liveSyncError" , // Do we need this or we can use liveSyncStopped event?
13
- liveSyncWatcherStarted : "liveSyncWatcherStarted" ,
14
- liveSyncWatcherStopped : "liveSyncWatcherStopped" ,
15
- liveSyncFileChangedEvent : "liveSyncFileChangedEvent" ,
16
- liveSyncOperationStartingEvent : "liveSyncOperationStartedEvent"
11
+ liveSyncError : "error" , // Do we need this or we can use liveSyncStopped event?
12
+ liveSyncFileChangedEvent : "fileChanged" ,
13
+ liveSyncCompleted : "liveSyncCompleted"
17
14
} ;
18
15
19
16
// TODO: emit events for "successfull livesync", "stoppedLivesync",
@@ -39,8 +36,6 @@ export class LiveSyncService extends EventEmitter implements ILiveSyncService {
39
36
@hook ( "liveSync" )
40
37
public async liveSync ( deviceDescriptors : ILiveSyncDeviceInfo [ ] ,
41
38
liveSyncData : ILiveSyncInfo ) : Promise < void > {
42
-
43
- this . emit ( LiveSyncEvents . liveSyncStarted , { projectDir : liveSyncData . projectDir , deviceIdentifiers : deviceDescriptors . map ( dd => dd . identifier ) } ) ;
44
39
// TODO: Initialize devicesService before that.
45
40
const projectData = this . $projectDataService . getProjectData ( liveSyncData . projectDir ) ;
46
41
await this . initialSync ( projectData , deviceDescriptors , liveSyncData ) ;
@@ -66,16 +61,30 @@ export class LiveSyncService extends EventEmitter implements ILiveSyncService {
66
61
liveSyncProcessInfo . watcher . close ( ) ;
67
62
}
68
63
69
- delete this . liveSyncProcessesInfo [ projectDir ] ;
64
+ if ( liveSyncProcessInfo . actionsChain ) {
65
+ await liveSyncProcessInfo . actionsChain ;
66
+ }
67
+
68
+ liveSyncProcessInfo . isStopped = true ;
70
69
71
70
// Kill typescript watcher
71
+ // TODO: Pass the projectDir in hooks args.
72
72
await this . $hooksService . executeAfterHooks ( 'watch' ) ;
73
+
74
+ this . emit ( LiveSyncEvents . liveSyncStopped , { projectDir } ) ;
73
75
}
74
76
}
75
77
76
78
protected async refreshApplication ( projectData : IProjectData , liveSyncResultInfo : ILiveSyncResultInfo ) : Promise < void > {
77
79
const platformLiveSyncService = this . getLiveSyncService ( liveSyncResultInfo . deviceAppData . platform ) ;
78
80
await platformLiveSyncService . refreshApplication ( projectData , liveSyncResultInfo ) ;
81
+
82
+ this . emit ( LiveSyncEvents . liveSyncCompleted , {
83
+ projectDir : projectData . projectDir ,
84
+ applicationIdentifier : projectData . projectId ,
85
+ syncedFiles : liveSyncResultInfo . modifiedFilesData . map ( m => m . getLocalPath ( ) ) ,
86
+ deviceIdentifier : liveSyncResultInfo . deviceAppData . device . deviceInfo . identifier
87
+ } ) ;
79
88
}
80
89
81
90
// TODO: Register both livesync services in injector
@@ -140,7 +149,6 @@ export class LiveSyncService extends EventEmitter implements ILiveSyncService {
140
149
141
150
const liveSyncResultInfo = await this . getLiveSyncService ( platform ) . fullSync ( { projectData, device, syncAllFiles : liveSyncData . watchAllFiles , useLiveEdit : liveSyncData . useLiveEdit } ) ;
142
151
await this . refreshApplication ( projectData , liveSyncResultInfo ) ;
143
- //await device.applicationManager.restartApplication(projectData.projectId, projectData.projectName);
144
152
} ;
145
153
146
154
await this . $devicesService . execute ( deviceAction , ( device : Mobile . IDevice ) => _ . some ( deviceDescriptors , deviceDescriptor => deviceDescriptor . identifier === device . deviceInfo . identifier ) ) ;
@@ -220,9 +228,16 @@ export class LiveSyncService extends EventEmitter implements ILiveSyncService {
220
228
this . $logger . info ( "Try saving it again or restart the livesync operation." ) ;
221
229
// we can remove the descriptor from action:
222
230
const allErrors = err . allErrors ;
223
- console . log ( allErrors ) ;
224
231
_ . each ( allErrors , ( deviceError : any ) => {
225
- console . log ( "for error: " , deviceError , " device ID: " , deviceError . deviceIdentifier ) ;
232
+ this . $logger . warn ( `Unable to apply changes for device: ${ deviceError . deviceIdentifier } . Error is: ${ deviceError . message } .` ) ;
233
+
234
+ this . emit ( LiveSyncEvents . liveSyncError , {
235
+ error : deviceError ,
236
+ deviceIdentifier : deviceError . deviceIdentifier ,
237
+ projectDir : projectData . projectDir ,
238
+ applicationIdentifier : projectData . projectId
239
+ } ) ;
240
+
226
241
removeDeviceDescriptor ( deviceError . deviceIdentifier ) ;
227
242
} ) ;
228
243
}
@@ -245,12 +260,18 @@ export class LiveSyncService extends EventEmitter implements ILiveSyncService {
245
260
ignored : [ "**/.*" , ".*" ] // hidden files
246
261
} ;
247
262
248
- this . emit ( LiveSyncEvents . liveSyncWatcherStarted , { projectDir : liveSyncData . projectDir , deviceIdentifiers : deviceDescriptors . map ( dd => dd . identifier ) , watcherOptions, } ) ;
249
-
250
263
const watcher = choki . watch ( pattern , watcherOptions )
251
264
. on ( "all" , async ( event : string , filePath : string ) => {
252
265
clearTimeout ( timeoutTimer ) ;
253
266
267
+ this . emit ( LiveSyncEvents . liveSyncFileChangedEvent , {
268
+ projectDir : liveSyncData . projectDir ,
269
+ applicationIdentifier : projectData . projectId ,
270
+ deviceIdentifiers : deviceDescriptors . map ( dd => dd . identifier ) ,
271
+ modifiedFile : filePath ,
272
+ event
273
+ } ) ;
274
+
254
275
filePath = path . join ( liveSyncData . projectDir , filePath ) ;
255
276
256
277
this . $logger . trace ( `Chokidar raised event ${ event } for ${ filePath } .` ) ;
0 commit comments