@@ -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 ) . 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,27 +95,50 @@ export class ProjectService implements IProjectService {
93
95
} ) . future < void > ( ) ( ) ;
94
96
}
95
97
96
- private mergeProjectAndTemplateProperties ( projectDir : string , templatePath : string ) : void {
97
- let templatePackageJsonPath = path . join ( templatePath , constants . PACKAGE_JSON_FILE_NAME ) ;
98
-
99
- if ( this . $fs . exists ( templatePackageJsonPath ) ) {
100
- let projectPackageJsonPath = path . join ( projectDir , constants . PACKAGE_JSON_FILE_NAME ) ;
101
- let projectPackageJsonData = this . $fs . readJson ( projectPackageJsonPath ) ;
102
- this . $logger . trace ( "Initial project package.json data: " , projectPackageJsonData ) ;
103
- let templatePackageJsonData = this . $fs . readJson ( templatePackageJsonPath ) ;
104
- if ( projectPackageJsonData . dependencies || templatePackageJsonData . dependencies ) {
105
- projectPackageJsonData . dependencies = this . mergeDependencies ( projectPackageJsonData . dependencies , templatePackageJsonData . dependencies ) ;
98
+ private getDataFromJson ( templatePath : string ) : IFuture < any > {
99
+ return ( ( ) => {
100
+ let templatePackageJsonPath = path . join ( templatePath , constants . PACKAGE_JSON_FILE_NAME ) ;
101
+ if ( this . $fs . exists ( templatePackageJsonPath ) ) {
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
106
}
107
+ return null ;
108
+ } ) . future < void > ( ) ( ) ;
109
+ }
107
110
108
- if ( projectPackageJsonData . devDependencies || templatePackageJsonData . devDependencies ) {
109
- projectPackageJsonData . devDependencies = this . mergeDependencies ( projectPackageJsonData . devDependencies , templatePackageJsonData . devDependencies ) ;
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
+ }
110
118
}
111
119
112
- this . $logger . trace ( "New project package.json data: " , projectPackageJsonData ) ;
113
- this . $fs . writeJson ( projectPackageJsonPath , projectPackageJsonData ) ;
114
- } else {
115
- this . $logger . trace ( `Template ${ templatePath } does not have ${ constants . PACKAGE_JSON_FILE_NAME } file.` ) ;
116
- }
120
+ this . $logger . trace ( "Deleting unnecessary information from template json." ) ;
121
+ this . $fs . writeJson ( extractedTemplatePackageJsonPath , templatePackageJsonData ) ;
122
+ } ) . future < any > ( ) ( ) ;
123
+ }
124
+
125
+ private mergeProjectAndTemplateProperties ( projectDir : string , templatePackageJsonData : any ) : IFuture < void > {
126
+ return ( ( ) => {
127
+ if ( templatePackageJsonData ) {
128
+ let projectPackageJsonPath = path . join ( projectDir , constants . PACKAGE_JSON_FILE_NAME ) ;
129
+ let projectPackageJsonData = this . $fs . readJson ( projectPackageJsonPath ) . wait ( ) ;
130
+ this . $logger . trace ( "Initial project package.json data: " , projectPackageJsonData ) ;
131
+ if ( projectPackageJsonData . dependencies || templatePackageJsonData . dependencies ) {
132
+ projectPackageJsonData . dependencies = this . mergeDependencies ( projectPackageJsonData . dependencies , templatePackageJsonData . dependencies ) ;
133
+ }
134
+
135
+ if ( projectPackageJsonData . devDependencies || templatePackageJsonData . devDependencies ) {
136
+ projectPackageJsonData . devDependencies = this . mergeDependencies ( projectPackageJsonData . devDependencies , templatePackageJsonData . devDependencies ) ;
137
+ }
138
+ this . $logger . trace ( "New project package.json data: " , projectPackageJsonData ) ;
139
+ this . $fs . writeJson ( projectPackageJsonPath , projectPackageJsonData ) ;
140
+ }
141
+ } ) . future < void > ( ) ( ) ;
117
142
}
118
143
119
144
private mergeDependencies ( projectDependencies : IStringDictionary , templateDependencies : IStringDictionary ) : IStringDictionary {
0 commit comments