@@ -54,17 +54,21 @@ export class ProjectService implements IProjectService {
54
54
55
55
private getProjectData ( ) : IFuture < IProjectData > {
56
56
return ( ( ) => {
57
- var projectFilePath = path . join ( this . projectDir , this . $config . PROJECT_FILE_NAME ) ;
58
- var projectData :IProjectData = {
59
- projectDir : this . projectDir ,
60
- platformsDir : path . join ( this . projectDir , "platforms" ) ,
61
- projectFilePath : path . join ( this . projectDir , this . $config . PROJECT_FILE_NAME )
62
- } ;
63
-
64
- if ( this . $fs . exists ( projectFilePath ) . wait ( ) ) {
65
- var fileContent = this . $fs . readJson ( projectFilePath ) . wait ( ) ;
66
- projectData . projectId = fileContent . id ;
67
- projectData . projectName = path . basename ( this . projectDir ) ;
57
+ var projectData : IProjectData = null ;
58
+
59
+ if ( this . projectDir ) {
60
+ projectData = {
61
+ projectDir : this . projectDir ,
62
+ platformsDir : path . join ( this . projectDir , "platforms" ) ,
63
+ projectFilePath : path . join ( this . projectDir , this . $config . PROJECT_FILE_NAME )
64
+ } ;
65
+ var projectFilePath = path . join ( this . projectDir , this . $config . PROJECT_FILE_NAME ) ;
66
+
67
+ if ( this . $fs . exists ( projectFilePath ) . wait ( ) ) {
68
+ var fileContent = this . $fs . readJson ( projectFilePath ) . wait ( ) ;
69
+ projectData . projectId = fileContent . id ;
70
+ projectData . projectName = path . basename ( this . projectDir ) ;
71
+ }
68
72
}
69
73
70
74
return projectData ;
@@ -239,7 +243,7 @@ export class ProjectService implements IProjectService {
239
243
$injector . register ( "projectService" , ProjectService ) ;
240
244
241
245
class AndroidProjectService implements IPlatformProjectService {
242
- private cachedFrameworkDir : string = null ;
246
+ private frameworkDir : string = null ;
243
247
244
248
constructor ( private $fs : IFileSystem ,
245
249
private $errors : IErrors ,
@@ -250,16 +254,18 @@ class AndroidProjectService implements IPlatformProjectService {
250
254
251
255
public createProject ( projectData : IProjectData ) : IFuture < void > {
252
256
return ( ( ) => {
257
+ this . frameworkDir = this . getFrameworkDir ( projectData ) . wait ( ) ;
258
+
253
259
var packageName = projectData . projectId ;
254
260
var projectDir = path . join ( projectData . projectDir , "platforms" , "android" ) ;
255
261
256
262
this . validatePackageName ( packageName ) ;
257
263
this . validateProjectName ( projectData . projectName ) ;
258
264
259
- var targetApi = this . getTarget ( ) . wait ( ) ;
260
-
261
265
this . checkRequirements ( ) . wait ( ) ;
262
266
267
+ var targetApi = this . getTarget ( ) . wait ( ) ;
268
+
263
269
// Log the values for project
264
270
this . $logger . trace ( "Creating NativeScript project for the Android platform" ) ;
265
271
this . $logger . trace ( "Path: %s" , projectData . projectDir ) ;
@@ -269,13 +275,15 @@ class AndroidProjectService implements IPlatformProjectService {
269
275
270
276
this . $logger . out ( "Copying template files..." ) ;
271
277
272
- shell . cp ( "-r" , path . join ( this . frameworkDir . wait ( ) , "assets" ) , projectDir ) ;
273
- shell . cp ( "-r" , path . join ( this . frameworkDir . wait ( ) , "gen" ) , projectDir ) ;
274
- shell . cp ( "-r" , path . join ( this . frameworkDir . wait ( ) , "libs" ) , projectDir ) ;
275
- shell . cp ( "-r" , path . join ( this . frameworkDir . wait ( ) , "res" ) , projectDir ) ;
278
+ shell . cp ( "-r" , path . join ( this . frameworkDir , "assets" ) , projectDir ) ;
279
+ shell . cp ( "-r" , path . join ( this . frameworkDir , "gen" ) , projectDir ) ;
280
+ shell . cp ( "-r" , path . join ( this . frameworkDir , "libs" ) , projectDir ) ;
281
+ shell . cp ( "-r" , path . join ( this . frameworkDir , "res" ) , projectDir ) ;
282
+
283
+ shell . cp ( "-f" , path . join ( this . frameworkDir , ".project" ) , projectDir ) ;
284
+ shell . cp ( "-f" , path . join ( this . frameworkDir , "AndroidManifest.xml" ) , projectDir ) ;
276
285
277
- shell . cp ( "-f" , path . join ( this . frameworkDir . wait ( ) , ".project" ) , projectDir ) ;
278
- shell . cp ( "-f" , path . join ( this . frameworkDir . wait ( ) , "AndroidManifest.xml" ) , projectDir ) ;
286
+ this . $fs . deleteDirectory ( path . join ( projectData . platformsDir , "android" , "node_modules" ) ) . wait ( ) ;
279
287
280
288
// Interpolate the activity name and package
281
289
var stringsFilePath = path . join ( projectDir , 'res' , 'values' , 'strings.xml' ) ;
@@ -327,21 +335,16 @@ class AndroidProjectService implements IPlatformProjectService {
327
335
}
328
336
}
329
337
330
- private get frameworkDir ( ) : IFuture < string > {
338
+ private getFrameworkDir ( projectData : IProjectData ) : IFuture < string > {
331
339
return ( ( ) => {
332
- if ( ! this . cachedFrameworkDir ) {
333
- var androidFrameworkPath = this . $projectTemplatesService . androidFrameworkPath . wait ( ) ;
334
- this . cachedFrameworkDir = path . join ( androidFrameworkPath , ProjectService . PROJECT_FRAMEWORK_DIR ) ;
335
- }
336
-
337
- return this . cachedFrameworkDir ;
338
-
340
+ var androidFrameworkPath = this . $projectTemplatesService . getAndroidFrameworkPath ( path . join ( projectData . platformsDir , "android" ) ) . wait ( ) ;
341
+ return path . join ( androidFrameworkPath , "framework" ) ;
339
342
} ) . future < string > ( ) ( ) ;
340
343
}
341
344
342
345
private getTarget ( ) : IFuture < string > {
343
346
return ( ( ) => {
344
- var projectPropertiesFilePath = path . join ( this . frameworkDir . wait ( ) , "project.properties" ) ;
347
+ var projectPropertiesFilePath = path . join ( this . frameworkDir , "project.properties" ) ;
345
348
346
349
if ( this . $fs . exists ( projectPropertiesFilePath ) . wait ( ) ) {
347
350
var properties = this . $propertiesParser . createEditor ( projectPropertiesFilePath ) . wait ( ) ;
0 commit comments