@@ -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 ) . wait ( ) ; //merging dependencies from template (dev && prod)
79
+ let templatePackageJsonData = this . getDataFromJson ( appPath ) . wait ( ) ;
80
+ this . mergeProjectAndTemplateProperties ( projectDir , templatePackageJsonData ) . wait ( ) ; //merging dependencies from template (dev && prod)
81
+ this . removeMergedDependencies ( projectDir , templatePackageJsonData ) . wait ( ) ;
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,14 +95,39 @@ export class ProjectService implements IProjectService {
93
95
} ) . future < void > ( ) ( ) ;
94
96
}
95
97
96
- private mergeProjectAndTemplateProperties ( projectDir : string , templatePath : string ) : IFuture < void > {
98
+ private getDataFromJson ( templatePath : string ) : IFuture < any > {
97
99
return ( ( ) => {
98
100
let templatePackageJsonPath = path . join ( templatePath , constants . PACKAGE_JSON_FILE_NAME ) ;
99
101
if ( this . $fs . exists ( templatePackageJsonPath ) . wait ( ) ) {
102
+ let templatePackageJsonData = this . $fs . readJson ( templatePackageJsonPath ) . wait ( ) ;
103
+ return templatePackageJsonData ;
104
+ } else {
105
+ this . $logger . trace ( `Template ${ templatePath } does not have ${ constants . PACKAGE_JSON_FILE_NAME } file.` ) ;
106
+ }
107
+ return null ;
108
+ } ) . future < void > ( ) ( ) ;
109
+ }
110
+
111
+ private removeMergedDependencies ( projectDir : string , templatePackageJsonData : any ) : IFuture < void > {
112
+ return ( ( ) => {
113
+ let extractedTemplatePackageJsonPath = path . join ( projectDir , constants . APP_FOLDER_NAME , constants . PACKAGE_JSON_FILE_NAME ) ;
114
+ for ( let key in templatePackageJsonData ) {
115
+ if ( constants . PackageJsonKeysToKeep . indexOf ( key ) === - 1 ) {
116
+ delete templatePackageJsonData [ key ] ;
117
+ }
118
+ }
119
+
120
+ this . $logger . trace ( "Deleting unnecessary information from template json." ) ;
121
+ this . $fs . writeJson ( extractedTemplatePackageJsonPath , templatePackageJsonData ) . wait ( ) ;
122
+ } ) . future < any > ( ) ( ) ;
123
+ }
124
+
125
+ private mergeProjectAndTemplateProperties ( projectDir : string , templatePackageJsonData : any ) : IFuture < void > {
126
+ return ( ( ) => {
127
+ if ( templatePackageJsonData ) {
100
128
let projectPackageJsonPath = path . join ( projectDir , constants . PACKAGE_JSON_FILE_NAME ) ;
101
129
let projectPackageJsonData = this . $fs . readJson ( projectPackageJsonPath ) . wait ( ) ;
102
130
this . $logger . trace ( "Initial project package.json data: " , projectPackageJsonData ) ;
103
- let templatePackageJsonData = this . $fs . readJson ( templatePackageJsonPath ) . wait ( ) ;
104
131
if ( projectPackageJsonData . dependencies || templatePackageJsonData . dependencies ) {
105
132
projectPackageJsonData . dependencies = this . mergeDependencies ( projectPackageJsonData . dependencies , templatePackageJsonData . dependencies ) ;
106
133
}
@@ -111,8 +138,6 @@ export class ProjectService implements IProjectService {
111
138
112
139
this . $logger . trace ( "New project package.json data: " , projectPackageJsonData ) ;
113
140
this . $fs . writeJson ( projectPackageJsonPath , projectPackageJsonData ) . wait ( ) ;
114
- } else {
115
- this . $logger . trace ( `Template ${ templatePath } does not have ${ constants . PACKAGE_JSON_FILE_NAME } file.` ) ;
116
141
}
117
142
} ) . future < void > ( ) ( ) ;
118
143
}
0 commit comments