@@ -76,7 +76,9 @@ export class ProjectService implements IProjectService {
7676 try {
7777 //TODO: plamen5kov: move copy of template and npm uninstall in prepareTemplate logic
7878 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 ( ) ;
8082 this . $npm . install ( projectDir , projectDir , { "ignore-scripts" : this . $options . ignoreScripts } ) . wait ( ) ;
8183 selectedTemplate = selectedTemplate || "" ;
8284 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 {
9395 } ) . future < void > ( ) ( ) ;
9496 }
9597
96- private mergeProjectAndTemplateProperties ( projectDir : string , templatePath : string ) : IFuture < void > {
98+ private getDataFromJson ( templatePath : string ) : IFuture < any > {
9799 return ( ( ) => {
98100 let templatePackageJsonPath = path . join ( templatePath , constants . PACKAGE_JSON_FILE_NAME ) ;
99101 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 ) {
100128 let projectPackageJsonPath = path . join ( projectDir , constants . PACKAGE_JSON_FILE_NAME ) ;
101129 let projectPackageJsonData = this . $fs . readJson ( projectPackageJsonPath ) . wait ( ) ;
102130 this . $logger . trace ( "Initial project package.json data: " , projectPackageJsonData ) ;
103- let templatePackageJsonData = this . $fs . readJson ( templatePackageJsonPath ) . wait ( ) ;
104131 if ( projectPackageJsonData . dependencies || templatePackageJsonData . dependencies ) {
105132 projectPackageJsonData . dependencies = this . mergeDependencies ( projectPackageJsonData . dependencies , templatePackageJsonData . dependencies ) ;
106133 }
@@ -111,8 +138,6 @@ export class ProjectService implements IProjectService {
111138
112139 this . $logger . trace ( "New project package.json data: " , projectPackageJsonData ) ;
113140 this . $fs . writeJson ( projectPackageJsonPath , projectPackageJsonData ) . wait ( ) ;
114- } else {
115- this . $logger . trace ( `Template ${ templatePath } does not have ${ constants . PACKAGE_JSON_FILE_NAME } file.` ) ;
116141 }
117142 } ) . future < void > ( ) ( ) ;
118143 }
0 commit comments