@@ -11,6 +11,7 @@ export class ProjectService implements IProjectService {
11
11
private static DEFAULT_PROJECT_ID = "com.telerik.tns.HelloWorld" ;
12
12
private static DEFAULT_PROJECT_NAME = "HelloNativescript" ;
13
13
public static APP_FOLDER_NAME = "app" ;
14
+ private static APP_RESOURCES_FOLDER_NAME = "App_Resources" ;
14
15
public static PROJECT_FRAMEWORK_DIR = "framework" ;
15
16
16
17
public projectData : IProjectData = null ;
@@ -130,32 +131,41 @@ export class ProjectService implements IProjectService {
130
131
} ) . future < void > ( ) ( ) ;
131
132
}
132
133
133
- public prepareProject ( platform : string , platforms : string [ ] ) : IFuture < void > {
134
+ public prepareProject ( normalizedPlatformName : string , platforms : string [ ] ) : IFuture < void > {
134
135
return ( ( ) => {
136
+ var platform = normalizedPlatformName . toLowerCase ( ) ;
135
137
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
+ }
137
145
138
146
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
+
140
149
_ . 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 ) {
142
153
this . $fs . deleteFile ( fileName ) . wait ( ) ;
154
+ } else if ( platformInfo && platformInfo . onDeviceName ) {
155
+ this . $fs . rename ( fileName , path . join ( path . dirname ( fileName ) , platformInfo . onDeviceName ) ) . wait ( ) ;
143
156
}
144
157
} ) ;
145
- } ) . future < void > ( ) ( ) ;
146
- }
147
158
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 > ( ) ( ) ;
151
160
}
152
161
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 ) ;
155
164
var parsed = fileName . toLowerCase ( ) . match ( new RegExp ( regex , "i" ) ) ;
156
165
if ( parsed ) {
157
166
return {
158
- platform : parsed [ 2 ]
167
+ platform : parsed [ 2 ] ,
168
+ onDeviceName : parsed [ 1 ] + parsed [ 3 ]
159
169
} ;
160
170
}
161
171
return undefined ;
0 commit comments