@@ -11,20 +11,31 @@ export class AppFilesUpdater {
1111 ) {
1212 }
1313
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 ( ) ;
1617
17- beforeCopyAction ( sourceFiles ) ;
18+ updateAppOptions . beforeCopyAction ( sourceFiles ) ;
1819 this . copyAppSourceFiles ( sourceFiles ) ;
1920 }
2021
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 [ ] ;
2624
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 ) => {
2839 this . deleteDestinationItem ( directoryItem ) ;
2940 } ) ;
3041 }
0 commit comments