@@ -4,6 +4,8 @@ import path = require("path");
4
4
import options = require( "./../options" ) ;
5
5
import shell = require( "shelljs" ) ;
6
6
import osenv = require( "osenv" ) ;
7
+ import util = require( "util" ) ;
8
+ import helpers = require( "./../common/helpers" ) ;
7
9
8
10
export class ProjectService implements IProjectService {
9
11
private static DEFAULT_PROJECT_ID = "com.telerik.tns.HelloWorld" ;
@@ -149,12 +151,37 @@ export class ProjectService implements IProjectService {
149
151
} ) . future < void > ( ) ( ) ;
150
152
}
151
153
152
- public prepareProject ( platform : string ) : IFuture < void > {
154
+ public prepareProject ( platform : string , platforms : string [ ] ) : IFuture < void > {
153
155
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
+ } ) ;
155
166
} ) . future < void > ( ) ( ) ;
156
167
}
157
168
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
+
158
185
public buildProject ( platform : string ) : IFuture < void > {
159
186
return ( ( ) => {
160
187
this . executePlatformSpecificAction ( platform , "buildProject" ) . wait ( ) ;
@@ -259,14 +286,6 @@ class AndroidProjectService implements IAndroidProjectService {
259
286
} ) . future < any > ( ) ( ) ;
260
287
}
261
288
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
-
270
289
public buildProject ( projectData : IProjectData ) : IFuture < void > {
271
290
return ( ( ) => {
272
291
0 commit comments