@@ -10,15 +10,16 @@ import util = require("util");
10
10
11
11
export class ProjectService implements IProjectService {
12
12
13
- constructor ( private $errors : IErrors ,
13
+ constructor ( private $npm : INodePackageManager ,
14
+ private $errors : IErrors ,
14
15
private $fs : IFileSystem ,
15
16
private $logger : ILogger ,
16
17
private $projectDataService : IProjectDataService ,
17
18
private $projectHelper : IProjectHelper ,
18
19
private $projectNameValidator : IProjectNameValidator ,
19
20
private $projectTemplatesService : IProjectTemplatesService ,
20
21
private $options : IOptions ,
21
- private $tnsModulesService : ITNSModulesService ) { }
22
+ private $childProcess : IChildProcess ) { }
22
23
23
24
public createProject ( projectName : string ) : IFuture < void > {
24
25
return ( ( ) => {
@@ -77,21 +78,8 @@ export class ProjectService implements IProjectService {
77
78
appPath = defaultTemplatePath ;
78
79
}
79
80
80
- var tnsModulesVersion : string = null ;
81
- // Optional parameter has a higher priority than defined version in package.json
82
- if ( this . $options . tnsModulesVersion ) {
83
- tnsModulesVersion = this . $options . tnsModulesVersion ;
84
- }
85
- else {
86
- let coreModulesName = this . $tnsModulesService . npmTnsCoreModulesName ;
87
- tnsModulesVersion = this . $fs . readJson ( path . join ( appPath , constants . PACKAGE_JSON_FILE_NAME ) ) . wait ( ) [ coreModulesName ] [ "version" ] ;
88
- }
89
-
90
- // Download tns-core-modules via npm and get destination file path
91
- var tnsModulesResourcePath = this . $tnsModulesService . tnsModulesInstallationPath ( tnsModulesVersion ) . wait ( ) ;
92
-
93
81
try {
94
- this . createProjectCore ( projectDir , appPath , tnsModulesResourcePath , projectId ) . wait ( ) ;
82
+ this . createProjectCore ( projectDir , appPath , projectId ) . wait ( ) ;
95
83
} catch ( err ) {
96
84
this . $fs . deleteDirectory ( projectDir ) . wait ( ) ;
97
85
throw err ;
@@ -102,7 +90,7 @@ export class ProjectService implements IProjectService {
102
90
} ) . future < void > ( ) ( ) ;
103
91
}
104
92
105
- private createProjectCore ( projectDir : string , appSourcePath : string , tnsModulesPath : string , projectId : string ) : IFuture < void > {
93
+ private createProjectCore ( projectDir : string , appSourcePath : string , projectId : string ) : IFuture < void > {
106
94
return ( ( ) => {
107
95
this . $fs . ensureDirectoryExists ( projectDir ) . wait ( ) ;
108
96
@@ -114,25 +102,19 @@ export class ProjectService implements IProjectService {
114
102
} else {
115
103
shell . cp ( '-R' , path . join ( appSourcePath , "*" ) , appDestinationPath ) ;
116
104
}
117
-
118
- // Copy tns-core-modules package to node_modules destination directory
119
- let nodeModulesDestination = path . join ( appDestinationPath , constants . NODE_MODULES_FOLDER_NAME ) ;
120
- this . $fs . ensureDirectoryExists ( nodeModulesDestination ) . wait ( ) ;
121
- shell . cp ( '-Rf' , path . join ( tnsModulesPath , '*' ) , nodeModulesDestination ) ;
122
-
123
- let tnsModulesVersion = this . $fs . readJson ( path . join ( nodeModulesDestination , constants . PACKAGE_JSON_FILE_NAME ) ) . wait ( ) . version ;
124
105
125
- this . createBasicProjectStructure ( projectDir , projectId , tnsModulesVersion ) . wait ( ) ;
106
+ this . createBasicProjectStructure ( projectDir , projectId ) . wait ( ) ;
126
107
} ) . future < void > ( ) ( ) ;
127
108
}
128
109
129
- private createBasicProjectStructure ( projectDir : string , projectId : string , tnsModulesVersion : string ) : IFuture < void > {
110
+ private createBasicProjectStructure ( projectDir : string , projectId : string ) : IFuture < void > {
130
111
return ( ( ) => {
131
112
this . $fs . createDirectory ( path . join ( projectDir , "platforms" ) ) . wait ( ) ;
132
113
133
114
this . $projectDataService . initialize ( projectDir ) ;
134
115
this . $projectDataService . setValue ( "id" , projectId ) . wait ( ) ;
135
- this . $projectDataService . setValue ( this . $tnsModulesService . npmTnsCoreModulesName , { version : tnsModulesVersion } ) . wait ( ) ;
116
+ //Start child process because --save --save-exact option necessary when installing tns-core-modules.
117
+ this . $childProcess . exec ( "npm install " + constants . TNS_CORE_MODULES_NAME + " --save --save-exact" , { cwd : projectDir } ) . wait ( ) ;
136
118
} ) . future < void > ( ) ( ) ;
137
119
}
138
120
0 commit comments