@@ -11,20 +11,31 @@ export class AppFilesUpdater {
11
11
) {
12
12
}
13
13
14
- public updateApp ( beforeCopyAction : ( sourceFiles : string [ ] ) => void , filesToSync ?: string [ ] ) : void {
15
- const sourceFiles = filesToSync || this . resolveAppSourceFiles ( ) ;
14
+ public updateApp ( updateAppOptions : IUpdateAppOptions ) : void {
15
+ this . cleanDestinationApp ( updateAppOptions ) ;
16
+ const sourceFiles = updateAppOptions . filesToSync || this . resolveAppSourceFiles ( ) ;
16
17
17
- beforeCopyAction ( sourceFiles ) ;
18
+ updateAppOptions . beforeCopyAction ( sourceFiles ) ;
18
19
this . copyAppSourceFiles ( sourceFiles ) ;
19
20
}
20
21
21
- public cleanDestinationApp ( ) : void {
22
- // Delete the destination app in order to prevent EEXIST errors when symlinks are used.
23
- let destinationAppContents = this . readDestinationDir ( ) ;
24
- destinationAppContents = destinationAppContents . filter (
25
- ( directoryName : string ) => directoryName !== constants . TNS_MODULES_FOLDER_NAME ) ;
22
+ public cleanDestinationApp ( updateAppOptions ?: IUpdateAppOptions ) : void {
23
+ let itemsToRemove : string [ ] ;
26
24
27
- _ ( destinationAppContents ) . each ( ( directoryItem : string ) => {
25
+ if ( updateAppOptions && updateAppOptions . filesToRemove ) {
26
+ // We get here during LiveSync - we only want to get rid of files, that the file system watcher detected were deleted
27
+ itemsToRemove = updateAppOptions . filesToRemove . map ( fileToRemove => path . relative ( this . appSourceDirectoryPath , fileToRemove ) ) ;
28
+ } else {
29
+ // We get here during the initial sync before the file system watcher is even started
30
+ // delete everything and prepare everything anew just to be sure
31
+ // Delete the destination app in order to prevent EEXIST errors when symlinks are used.
32
+ itemsToRemove = this . readDestinationDir ( ) ;
33
+ itemsToRemove = itemsToRemove . filter (
34
+ ( directoryName : string ) => directoryName !== constants . TNS_MODULES_FOLDER_NAME ) ;
35
+
36
+ }
37
+
38
+ _ ( itemsToRemove ) . each ( ( directoryItem : string ) => {
28
39
this . deleteDestinationItem ( directoryItem ) ;
29
40
} ) ;
30
41
}
0 commit comments