@@ -6,9 +6,15 @@ import * as shell from "shelljs";
66import * as constants from "../constants" ;
77import * as helpers from "../common/helpers" ;
88import * as semver from "semver" ;
9+ import * as minimatch from "minimatch" ;
10+ import Future = require( "fibers/future" ) ;
911
1012export class PlatformService implements IPlatformService {
1113 private static TNS_MODULES_FOLDER_NAME = "tns_modules" ;
14+ private static EXCLUDE_FILES_PATTERN = [
15+ "**/*.js.map" ,
16+ "**/*.ts"
17+ ] ;
1218
1319 constructor ( private $devicesService : Mobile . IDevicesService ,
1420 private $errors : IErrors ,
@@ -174,22 +180,26 @@ export class PlatformService implements IPlatformService {
174180 . value ( ) ;
175181
176182 // Copy all files from app dir, but make sure to exclude tns_modules
177- let sourceFiles = this . $fs . readDirectory ( appSourceDirectoryPath ) . wait ( ) ;
183+ let sourceFiles = this . $fs . enumerateFilesInDirectorySync ( appSourceDirectoryPath ) ;
178184
179185 if ( this . $options . release ) {
180186 sourceFiles = sourceFiles . filter ( source => source !== 'tests' ) ;
181187 }
182188
183- let hasTnsModulesInAppFolder = _ . contains ( sourceFiles , constants . TNS_MODULES_FOLDER_NAME ) ;
189+ let hasTnsModulesInAppFolder = this . $fs . exists ( path . join ( appSourceDirectoryPath , constants . TNS_MODULES_FOLDER_NAME ) ) . wait ( ) ;
184190 if ( hasTnsModulesInAppFolder && this . $projectData . dependencies && this . $projectData . dependencies [ constants . TNS_CORE_MODULES_NAME ] ) {
185191 this . $logger . warn ( "You have tns_modules dir in your app folder and tns-core-modules in your package.json file. Tns_modules dir in your app folder will not be used and you can safely remove it." ) ;
186- sourceFiles . filter ( source => source !== constants . TNS_MODULES_FOLDER_NAME )
187- . map ( source => path . join ( appSourceDirectoryPath , source ) )
188- . forEach ( source => shell . cp ( "-Rf" , source , appDestinationDirectoryPath ) ) ;
189- } else {
190- shell . cp ( "-Rf" , path . join ( appSourceDirectoryPath , "*" ) , appDestinationDirectoryPath ) ;
192+ sourceFiles = sourceFiles . filter ( source => ! minimatch ( source , `**/${ constants . TNS_MODULES_FOLDER_NAME } /**` , { nocase : true } ) ) ;
191193 }
192194
195+ // Remove .ts and .js.map files
196+ PlatformService . EXCLUDE_FILES_PATTERN . forEach ( pattern => sourceFiles = sourceFiles . filter ( file => ! minimatch ( file , pattern , { nocase : true } ) ) ) ;
197+ let copyFileFutures = sourceFiles . map ( source => {
198+ let destinationFile = path . join ( appDestinationDirectoryPath , path . relative ( appSourceDirectoryPath , source ) ) ;
199+ return this . $fs . copyFile ( source , destinationFile ) ;
200+ } ) ;
201+ Future . wait ( copyFileFutures ) ;
202+
193203 // Copy App_Resources to project root folder
194204 this . $fs . ensureDirectoryExists ( platformData . platformProjectService . getAppResourcesDestinationDirectoryPath ( ) . wait ( ) ) . wait ( ) ; // Should be deleted
195205 let appResourcesDirectoryPath = path . join ( appDestinationDirectoryPath , constants . APP_RESOURCES_FOLDER_NAME ) ;
0 commit comments