@@ -76,9 +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- let templatePackageJsonData = this . getDataFromJson ( appPath ) . wait ( ) ;
80- this . mergeProjectAndTemplateProperties ( projectDir , templatePackageJsonData ) . wait ( ) ; //merging dependencies from template (dev && prod)
81- this . removeMergedDependencies ( projectDir , templatePackageJsonData ) . wait ( ) ;
79+ let templatePackageJsonData = this . getDataFromJson ( appPath ) ;
80+ this . mergeProjectAndTemplateProperties ( projectDir , templatePackageJsonData ) ; //merging dependencies from template (dev && prod)
81+ this . removeMergedDependencies ( projectDir , templatePackageJsonData ) ;
8282 this . $npm . install ( projectDir , projectDir , { "ignore-scripts" : this . $options . ignoreScripts } ) . wait ( ) ;
8383 selectedTemplate = selectedTemplate || "" ;
8484 let templateName = ( constants . RESERVED_TEMPLATE_NAMES [ selectedTemplate . toLowerCase ( ) ] || selectedTemplate /*user template*/ ) || constants . RESERVED_TEMPLATE_NAMES [ "default" ] ;
@@ -95,50 +95,44 @@ export class ProjectService implements IProjectService {
9595 } ) . future < void > ( ) ( ) ;
9696 }
9797
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- }
107- return null ;
108- } ) . future < void > ( ) ( ) ;
98+ private getDataFromJson ( templatePath : string ) : any {
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 ;
109107 }
110108
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- }
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 ] ;
118114 }
115+ }
119116
120- this . $logger . trace ( "Deleting unnecessary information from template json." ) ;
121- this . $fs . writeJson ( extractedTemplatePackageJsonPath , templatePackageJsonData ) ;
122- } ) . future < any > ( ) ( ) ;
117+ this . $logger . trace ( "Deleting unnecessary information from template json." ) ;
118+ this . $fs . writeJson ( extractedTemplatePackageJsonPath , templatePackageJsonData ) ;
123119 }
124120
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- }
121+ private mergeProjectAndTemplateProperties ( projectDir : string , templatePackageJsonData : any ) : void {
122+ if ( templatePackageJsonData ) {
123+ let projectPackageJsonPath = path . join ( projectDir , constants . PACKAGE_JSON_FILE_NAME ) ;
124+ let projectPackageJsonData = this . $fs . readJson ( projectPackageJsonPath ) ;
125+ this . $logger . trace ( "Initial project package.json data: " , projectPackageJsonData ) ;
126+ if ( projectPackageJsonData . dependencies || templatePackageJsonData . dependencies ) {
127+ projectPackageJsonData . dependencies = this . mergeDependencies ( projectPackageJsonData . dependencies , templatePackageJsonData . dependencies ) ;
128+ }
134129
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 ) ;
130+ if ( projectPackageJsonData . devDependencies || templatePackageJsonData . devDependencies ) {
131+ projectPackageJsonData . devDependencies = this . mergeDependencies ( projectPackageJsonData . devDependencies , templatePackageJsonData . devDependencies ) ;
140132 }
141- } ) . future < void > ( ) ( ) ;
133+ this . $logger . trace ( "New project package.json data: " , projectPackageJsonData ) ;
134+ this . $fs . writeJson ( projectPackageJsonPath , projectPackageJsonData ) ;
135+ }
142136 }
143137
144138 private mergeDependencies ( projectDependencies : IStringDictionary , templateDependencies : IStringDictionary ) : IStringDictionary {
0 commit comments