@@ -76,7 +76,9 @@ export class ProjectService implements IProjectService {
76
76
try {
77
77
//TODO: plamen5kov: move copy of template and npm uninstall in prepareTemplate logic
78
78
this . createProjectCore ( projectDir , appPath , projectId ) . wait ( ) ;
79
- this . mergeProjectAndTemplateProperties ( projectDir , appPath ) ; //merging dependencies from template (dev && prod)
79
+ let templatePackageJsonData = this . getDataFromJson ( appPath ) ;
80
+ this . mergeProjectAndTemplateProperties ( projectDir , templatePackageJsonData ) ; //merging dependencies from template (dev && prod)
81
+ this . removeMergedDependencies ( projectDir , templatePackageJsonData ) ;
80
82
this . $npm . install ( projectDir , projectDir , { "ignore-scripts" : this . $options . ignoreScripts } ) . wait ( ) ;
81
83
selectedTemplate = selectedTemplate || "" ;
82
84
let templateName = ( constants . RESERVED_TEMPLATE_NAMES [ selectedTemplate . toLowerCase ( ) ] || selectedTemplate /*user template*/ ) || constants . RESERVED_TEMPLATE_NAMES [ "default" ] ;
@@ -93,26 +95,43 @@ export class ProjectService implements IProjectService {
93
95
} ) . future < void > ( ) ( ) ;
94
96
}
95
97
96
- private mergeProjectAndTemplateProperties ( projectDir : string , templatePath : string ) : void {
98
+ private getDataFromJson ( templatePath : string ) : any {
97
99
let templatePackageJsonPath = path . join ( templatePath , constants . PACKAGE_JSON_FILE_NAME ) ;
100
+ if ( this . $fs . exists ( templatePackageJsonPath ) ) {
101
+ let templatePackageJsonData = this . $fs . readJson ( templatePackageJsonPath ) ;
102
+ return templatePackageJsonData ;
103
+ } else {
104
+ this . $logger . trace ( `Template ${ templatePath } does not have ${ constants . PACKAGE_JSON_FILE_NAME } file.` ) ;
105
+ }
106
+ return null ;
107
+ }
108
+
109
+ private removeMergedDependencies ( projectDir : string , templatePackageJsonData : any ) : void {
110
+ let extractedTemplatePackageJsonPath = path . join ( projectDir , constants . APP_FOLDER_NAME , constants . PACKAGE_JSON_FILE_NAME ) ;
111
+ for ( let key in templatePackageJsonData ) {
112
+ if ( constants . PackageJsonKeysToKeep . indexOf ( key ) === - 1 ) {
113
+ delete templatePackageJsonData [ key ] ;
114
+ }
115
+ }
116
+
117
+ this . $logger . trace ( "Deleting unnecessary information from template json." ) ;
118
+ this . $fs . writeJson ( extractedTemplatePackageJsonPath , templatePackageJsonData ) ;
119
+ }
98
120
99
- if ( this . $fs . exists ( templatePackageJsonPath ) ) {
121
+ private mergeProjectAndTemplateProperties ( projectDir : string , templatePackageJsonData : any ) : void {
122
+ if ( templatePackageJsonData ) {
100
123
let projectPackageJsonPath = path . join ( projectDir , constants . PACKAGE_JSON_FILE_NAME ) ;
101
124
let projectPackageJsonData = this . $fs . readJson ( projectPackageJsonPath ) ;
102
125
this . $logger . trace ( "Initial project package.json data: " , projectPackageJsonData ) ;
103
- let templatePackageJsonData = this . $fs . readJson ( templatePackageJsonPath ) ;
104
- if ( projectPackageJsonData . dependencies || templatePackageJsonData . dependencies ) {
126
+ if ( projectPackageJsonData . dependencies || templatePackageJsonData . dependencies ) {
105
127
projectPackageJsonData . dependencies = this . mergeDependencies ( projectPackageJsonData . dependencies , templatePackageJsonData . dependencies ) ;
106
128
}
107
129
108
130
if ( projectPackageJsonData . devDependencies || templatePackageJsonData . devDependencies ) {
109
131
projectPackageJsonData . devDependencies = this . mergeDependencies ( projectPackageJsonData . devDependencies , templatePackageJsonData . devDependencies ) ;
110
132
}
111
-
112
133
this . $logger . trace ( "New project package.json data: " , projectPackageJsonData ) ;
113
134
this . $fs . writeJson ( projectPackageJsonPath , projectPackageJsonData ) ;
114
- } else {
115
- this . $logger . trace ( `Template ${ templatePath } does not have ${ constants . PACKAGE_JSON_FILE_NAME } file.` ) ;
116
135
}
117
136
}
118
137
0 commit comments