@@ -3,8 +3,7 @@ import * as shell from "shelljs";
3
3
import * as constants from "../constants" ;
4
4
import * as helpers from "../common/helpers" ;
5
5
import * as semver from "semver" ;
6
- import * as minimatch from "minimatch" ;
7
- import Future = require( "fibers/future" ) ;
6
+ import { AppFilesUpdater } from "./app-files-updater" ;
8
7
import * as temp from "temp" ;
9
8
temp . track ( ) ;
10
9
let clui = require ( "clui" ) ;
@@ -244,44 +243,18 @@ export class PlatformService implements IPlatformService {
244
243
this . $fs . ensureDirectoryExists ( appDestinationDirectoryPath ) . wait ( ) ;
245
244
let appSourceDirectoryPath = path . join ( this . $projectData . projectDir , constants . APP_FOLDER_NAME ) ;
246
245
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 ( ) ;
276
249
} ) ;
277
- Future . wait ( copyFileFutures ) ;
278
250
279
251
// 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
281
254
let appResourcesDirectoryPath = path . join ( appDestinationDirectoryPath , constants . APP_RESOURCES_FOLDER_NAME ) ;
282
255
if ( this . $fs . exists ( appResourcesDirectoryPath ) . wait ( ) ) {
283
256
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 ) ;
285
258
this . $fs . deleteDirectory ( appResourcesDirectoryPath ) . wait ( ) ;
286
259
}
287
260
@@ -316,6 +289,16 @@ export class PlatformService implements IPlatformService {
316
289
} ) . future < boolean > ( ) ( ) ;
317
290
}
318
291
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
+
319
302
public buildPlatform ( platform : string , buildConfig ?: IBuildConfig ) : IFuture < void > {
320
303
return ( ( ) => {
321
304
platform = platform . toLowerCase ( ) ;
0 commit comments