@@ -3,8 +3,7 @@ import * as shell from "shelljs";
33import * as constants from "../constants" ;
44import * as helpers from "../common/helpers" ;
55import * as semver from "semver" ;
6- import * as minimatch from "minimatch" ;
7- import Future = require( "fibers/future" ) ;
6+ import { AppFilesUpdater } from "./app-files-updater" ;
87import * as temp from "temp" ;
98temp . track ( ) ;
109let clui = require ( "clui" ) ;
@@ -244,44 +243,18 @@ export class PlatformService implements IPlatformService {
244243 this . $fs . ensureDirectoryExists ( appDestinationDirectoryPath ) . wait ( ) ;
245244 let appSourceDirectoryPath = path . join ( this . $projectData . projectDir , constants . APP_FOLDER_NAME ) ;
246245
247- // Delete the destination app in order to prevent EEXIST errors when symlinks are used.
248- let contents = this . $fs . readDirectory ( appDestinationDirectoryPath ) . wait ( ) ;
249-
250- _ ( contents )
251- . filter ( directoryName => directoryName !== constants . TNS_MODULES_FOLDER_NAME )
252- . each ( directoryName => this . $fs . deleteDirectory ( path . join ( appDestinationDirectoryPath , directoryName ) ) . wait ( ) ) ;
253-
254- // Copy all files from app dir, but make sure to exclude tns_modules
255- let sourceFiles = this . $fs . enumerateFilesInDirectorySync ( appSourceDirectoryPath , null , { includeEmptyDirectories : true } ) ;
256-
257- if ( this . $options . release ) {
258- let testsFolderPath = path . join ( appSourceDirectoryPath , 'tests' ) ;
259- sourceFiles = sourceFiles . filter ( source => source . indexOf ( testsFolderPath ) === - 1 ) ;
260- }
261-
262- // verify .xml files are well-formed
263- this . $xmlValidator . validateXmlFiles ( sourceFiles ) . wait ( ) ;
264-
265- // Remove .ts and .js.map files in release
266- if ( this . $options . release ) {
267- constants . LIVESYNC_EXCLUDED_FILE_PATTERNS . forEach ( pattern => sourceFiles = sourceFiles . filter ( file => ! minimatch ( file , pattern , { nocase : true } ) ) ) ;
268- }
269-
270- let copyFileFutures = sourceFiles . map ( source => {
271- let destinationPath = path . join ( appDestinationDirectoryPath , path . relative ( appSourceDirectoryPath , source ) ) ;
272- if ( this . $fs . getFsStats ( source ) . wait ( ) . isDirectory ( ) ) {
273- return this . $fs . createDirectory ( destinationPath ) ;
274- }
275- return this . $fs . copyFile ( source , destinationPath ) ;
246+ const appUpdater = new AppFilesUpdater ( appSourceDirectoryPath , appDestinationDirectoryPath , this . $options , this . $fs ) ;
247+ appUpdater . updateApp ( sourceFiles => {
248+ this . $xmlValidator . validateXmlFiles ( sourceFiles ) . wait ( ) ;
276249 } ) ;
277- Future . wait ( copyFileFutures ) ;
278250
279251 // Copy App_Resources to project root folder
280- this . $fs . ensureDirectoryExists ( platformData . platformProjectService . getAppResourcesDestinationDirectoryPath ( ) . wait ( ) ) . wait ( ) ; // Should be deleted
252+ const appResourcesDestination = platformData . platformProjectService . getAppResourcesDestinationDirectoryPath ( ) . wait ( ) ;
253+ this . $fs . ensureDirectoryExists ( appResourcesDestination ) . wait ( ) ; // Should be deleted
281254 let appResourcesDirectoryPath = path . join ( appDestinationDirectoryPath , constants . APP_RESOURCES_FOLDER_NAME ) ;
282255 if ( this . $fs . exists ( appResourcesDirectoryPath ) . wait ( ) ) {
283256 platformData . platformProjectService . prepareAppResources ( appResourcesDirectoryPath ) . wait ( ) ;
284- shell . cp ( "-Rf" , path . join ( appResourcesDirectoryPath , platformData . normalizedPlatformName , "*" ) , platformData . platformProjectService . getAppResourcesDestinationDirectoryPath ( ) . wait ( ) ) ;
257+ shell . cp ( "-Rf" , path . join ( appResourcesDirectoryPath , platformData . normalizedPlatformName , "*" ) , appResourcesDestination ) ;
285258 this . $fs . deleteDirectory ( appResourcesDirectoryPath ) . wait ( ) ;
286259 }
287260
@@ -316,6 +289,16 @@ export class PlatformService implements IPlatformService {
316289 } ) . future < boolean > ( ) ( ) ;
317290 }
318291
292+ public cleanDestinationApp ( platform : string ) : IFuture < void > {
293+ return ( ( ) => {
294+ const appSourceDirectoryPath = path . join ( this . $projectData . projectDir , constants . APP_FOLDER_NAME ) ;
295+ let platformData = this . $platformsData . getPlatformData ( platform ) ;
296+ let appDestinationDirectoryPath = path . join ( platformData . appDestinationDirectoryPath , constants . APP_FOLDER_NAME ) ;
297+ const appUpdater = new AppFilesUpdater ( appSourceDirectoryPath , appDestinationDirectoryPath , this . $options , this . $fs ) ;
298+ appUpdater . cleanDestinationApp ( ) ;
299+ } ) . future < void > ( ) ( ) ;
300+ }
301+
319302 public buildPlatform ( platform : string , buildConfig ?: IBuildConfig ) : IFuture < void > {
320303 return ( ( ) => {
321304 platform = platform . toLowerCase ( ) ;
0 commit comments