@@ -17,7 +17,8 @@ export class ProjectService implements IProjectService {
17
17
private $projectHelper : IProjectHelper ,
18
18
private $projectNameValidator : IProjectNameValidator ,
19
19
private $projectTemplatesService : IProjectTemplatesService ,
20
- private $options : IOptions ) { }
20
+ private $options : IOptions ,
21
+ private $tnsModulesService : ITNSModulesService ) { }
21
22
22
23
public createProject ( projectName : string ) : IFuture < void > {
23
24
return ( ( ) => {
@@ -75,21 +76,23 @@ export class ProjectService implements IProjectService {
75
76
this . $logger . trace ( "Copying NativeScript hello world application into %s" , appDirectory ) ;
76
77
appPath = defaultTemplatePath ;
77
78
}
79
+
80
+ // Download tns-core-modules via npm and get destination file path
81
+ var tnsModulesResourcePath = this . $tnsModulesService . tnsModulesInstallationPath ( tnsModulesVersion ) . wait ( ) ;
78
82
79
83
try {
80
- this . createProjectCore ( projectDir , appPath , projectId ) . wait ( ) ;
84
+ this . createProjectCore ( projectDir , appPath , tnsModulesResourcePath , projectId ) . wait ( ) ;
81
85
} catch ( err ) {
82
86
this . $fs . deleteDirectory ( projectDir ) . wait ( ) ;
83
87
throw err ;
84
88
}
85
89
86
-
87
90
this . $logger . out ( "Project %s was successfully created" , projectName ) ;
88
91
89
92
} ) . future < void > ( ) ( ) ;
90
93
}
91
94
92
- private createProjectCore ( projectDir : string , appSourcePath : string , projectId : string ) : IFuture < void > {
95
+ private createProjectCore ( projectDir : string , appSourcePath : string , tnsModulesPath : string , projectId : string ) : IFuture < void > {
93
96
return ( ( ) => {
94
97
this . $fs . ensureDirectoryExists ( projectDir ) . wait ( ) ;
95
98
@@ -101,16 +104,25 @@ export class ProjectService implements IProjectService {
101
104
} else {
102
105
shell . cp ( '-R' , path . join ( appSourcePath , "*" ) , appDestinationPath ) ;
103
106
}
104
- this . createBasicProjectStructure ( projectDir , projectId ) . wait ( ) ;
107
+
108
+ // Copy tns-core-modules package to node_modules destination directory
109
+ var nodeModulesDestination = path . join ( appDestinationPath , constants . NODE_MODULES_FOLDER_NAME ) ;
110
+ this . $fs . ensureDirectoryExists ( nodeModulesDestination ) . wait ( ) ;
111
+ shell . cp ( '-Rf' , path . join ( tnsModulesPath , '*' ) , nodeModulesDestination ) ;
112
+
113
+ var tnsModulesVersion = this . $fs . readJson ( path . join ( nodeModulesDestination , constants . PACKAGE_JSON_FILE_NAME ) ) . wait ( ) . version ;
114
+
115
+ this . createBasicProjectStructure ( projectDir , projectId , tnsModulesVersion ) . wait ( ) ;
105
116
} ) . future < void > ( ) ( ) ;
106
117
}
107
118
108
- private createBasicProjectStructure ( projectDir : string , projectId : string ) : IFuture < void > {
119
+ private createBasicProjectStructure ( projectDir : string , projectId : string , tnsModulesVersion : string ) : IFuture < void > {
109
120
return ( ( ) => {
110
121
this . $fs . createDirectory ( path . join ( projectDir , "platforms" ) ) . wait ( ) ;
111
122
112
123
this . $projectDataService . initialize ( projectDir ) ;
113
124
this . $projectDataService . setValue ( "id" , projectId ) . wait ( ) ;
125
+ this . $projectDataService . setValue ( this . $tnsModulesService . NPM_TNS_CORE_MODULES_NAME , { version : tnsModulesVersion } ) . wait ( ) ;
114
126
} ) . future < void > ( ) ( ) ;
115
127
}
116
128
0 commit comments