@@ -4,6 +4,8 @@ import path = require("path");
44import options = require( "./../options" ) ;
55import shell = require( "shelljs" ) ;
66import osenv = require( "osenv" ) ;
7+ import util = require( "util" ) ;
8+ import helpers = require( "./../common/helpers" ) ;
79
810export class ProjectService implements IProjectService {
911 private static DEFAULT_PROJECT_ID = "com.telerik.tns.HelloWorld" ;
@@ -149,12 +151,37 @@ export class ProjectService implements IProjectService {
149151 } ) . future < void > ( ) ( ) ;
150152 }
151153
152- public prepareProject ( platform : string ) : IFuture < void > {
154+ public prepareProject ( platform : string , platforms : string [ ] ) : IFuture < void > {
153155 return ( ( ) => {
154- this . executePlatformSpecificAction ( platform , "prepareProject" ) . wait ( ) ;
156+ var assetsDirectoryPath = path . join ( this . projectData . platformsDir , platform , "assets" ) ;
157+ shell . cp ( "-r" , path . join ( this . projectData . projectDir , ProjectService . APP_FOLDER_NAME ) , assetsDirectoryPath ) ;
158+
159+ var files = helpers . enumerateFilesInDirectorySync ( path . join ( assetsDirectoryPath , ProjectService . APP_FOLDER_NAME ) ) ;
160+ var pattern = util . format ( "%s%s%s" , path . sep , ProjectService . APP_FOLDER_NAME , path . sep ) ;
161+ _ . each ( files , fileName => {
162+ if ( ProjectService . shouldExcludeFile ( platform , platforms , fileName . split ( pattern ) [ 1 ] ) ) {
163+ this . $fs . deleteFile ( fileName ) . wait ( ) ;
164+ }
165+ } ) ;
155166 } ) . future < void > ( ) ( ) ;
156167 }
157168
169+ private static shouldExcludeFile ( platform : string , platforms : string [ ] , fileName : string ) : boolean {
170+ var platformInfo = ProjectService . parsePlatformSpecificFileName ( fileName , platforms ) ;
171+ return platformInfo && platformInfo . platform !== platform ;
172+ }
173+
174+ private static parsePlatformSpecificFileName ( fileName : string , platforms : string [ ] ) : any {
175+ var regex = util . format ( "^(.+?)\.(%s)(\..+?)$" , platforms . join ( "|" ) ) ;
176+ var parsed = fileName . toLowerCase ( ) . match ( new RegExp ( regex , "i" ) ) ;
177+ if ( parsed ) {
178+ return {
179+ platform : parsed [ 2 ]
180+ } ;
181+ }
182+ return undefined ;
183+ }
184+
158185 public buildProject ( platform : string ) : IFuture < void > {
159186 return ( ( ) => {
160187 this . executePlatformSpecificAction ( platform , "buildProject" ) . wait ( ) ;
@@ -259,14 +286,6 @@ class AndroidProjectService implements IAndroidProjectService {
259286 } ) . future < any > ( ) ( ) ;
260287 }
261288
262- public prepareProject ( projectData : IProjectData ) : IFuture < void > {
263- return ( ( ) => {
264- var projectDir = path . join ( projectData . projectDir , "platforms" , "android" ) ;
265- // Copy app into assets
266- shell . cp ( "-r" , path . join ( projectData . projectDir , ProjectService . APP_FOLDER_NAME ) , path . join ( projectDir , "assets" ) ) ;
267- } ) . future < void > ( ) ( ) ;
268- }
269-
270289 public buildProject ( projectData : IProjectData ) : IFuture < void > {
271290 return ( ( ) => {
272291
0 commit comments