@@ -11,6 +11,7 @@ export class ProjectService implements IProjectService {
1111 private static DEFAULT_PROJECT_ID = "com.telerik.tns.HelloWorld" ;
1212 private static DEFAULT_PROJECT_NAME = "HelloNativescript" ;
1313 public static APP_FOLDER_NAME = "app" ;
14+ private static APP_RESOURCES_FOLDER_NAME = "App_Resources" ;
1415 public static PROJECT_FRAMEWORK_DIR = "framework" ;
1516
1617 public projectData : IProjectData = null ;
@@ -130,32 +131,41 @@ export class ProjectService implements IProjectService {
130131 } ) . future < void > ( ) ( ) ;
131132 }
132133
133- public prepareProject ( platform : string , platforms : string [ ] ) : IFuture < void > {
134+ public prepareProject ( normalizedPlatformName : string , platforms : string [ ] ) : IFuture < void > {
134135 return ( ( ) => {
136+ var platform = normalizedPlatformName . toLowerCase ( ) ;
135137 var assetsDirectoryPath = path . join ( this . projectData . platformsDir , platform , "assets" ) ;
136- shell . cp ( "-r" , path . join ( this . projectData . projectDir , ProjectService . APP_FOLDER_NAME ) , assetsDirectoryPath ) ;
138+ var appResourcesDirectoryPath = path . join ( assetsDirectoryPath , ProjectService . APP_FOLDER_NAME , ProjectService . APP_RESOURCES_FOLDER_NAME ) ;
139+ shell . cp ( "-r" , path . join ( this . projectData . projectDir , ProjectService . APP_FOLDER_NAME ) , assetsDirectoryPath ) ;
140+
141+ if ( this . $fs . exists ( appResourcesDirectoryPath ) . wait ( ) ) {
142+ shell . cp ( "-r" , path . join ( appResourcesDirectoryPath , normalizedPlatformName , "*" ) , path . join ( this . projectData . platformsDir , platform , "res" ) ) ;
143+ this . $fs . deleteDirectory ( appResourcesDirectoryPath ) . wait ( ) ;
144+ }
137145
138146 var files = helpers . enumerateFilesInDirectorySync ( path . join ( assetsDirectoryPath , ProjectService . APP_FOLDER_NAME ) ) ;
139- var pattern = util . format ( "%s%s%s" , path . sep , ProjectService . APP_FOLDER_NAME , path . sep ) ;
147+ var platformsAsString = platforms . join ( "|" ) ;
148+
140149 _ . each ( files , fileName => {
141- if ( ProjectService . shouldExcludeFile ( platform , platforms , fileName . split ( pattern ) [ 1 ] ) ) {
150+ var platformInfo = ProjectService . parsePlatformSpecificFileName ( path . basename ( fileName ) , platformsAsString ) ;
151+ var shouldExcludeFile = platformInfo && platformInfo . platform !== platform ;
152+ if ( shouldExcludeFile ) {
142153 this . $fs . deleteFile ( fileName ) . wait ( ) ;
154+ } else if ( platformInfo && platformInfo . onDeviceName ) {
155+ this . $fs . rename ( fileName , path . join ( path . dirname ( fileName ) , platformInfo . onDeviceName ) ) . wait ( ) ;
143156 }
144157 } ) ;
145- } ) . future < void > ( ) ( ) ;
146- }
147158
148- private static shouldExcludeFile ( platform : string , platforms : string [ ] , fileName : string ) : boolean {
149- var platformInfo = ProjectService . parsePlatformSpecificFileName ( fileName , platforms ) ;
150- return platformInfo && platformInfo . platform !== platform ;
159+ } ) . future < void > ( ) ( ) ;
151160 }
152161
153- private static parsePlatformSpecificFileName ( fileName : string , platforms : string [ ] ) : any {
154- var regex = util . format ( "^(.+?)\.(%s)(\..+?)$" , platforms . join ( "|" ) ) ;
162+ private static parsePlatformSpecificFileName ( fileName : string , platforms : string ) : any {
163+ var regex = util . format ( "^(.+?)\.(%s)(\..+?)$" , platforms ) ;
155164 var parsed = fileName . toLowerCase ( ) . match ( new RegExp ( regex , "i" ) ) ;
156165 if ( parsed ) {
157166 return {
158- platform : parsed [ 2 ]
167+ platform : parsed [ 2 ] ,
168+ onDeviceName : parsed [ 1 ] + parsed [ 3 ]
159169 } ;
160170 }
161171 return undefined ;
0 commit comments