1- import { ng } from '../../utils/process' ;
2- import { readFile } from '../../utils/fs' ;
1+ import { ng , silentNpm } from '../../utils/process' ;
2+ import { readFile , writeFile } from '../../utils/fs' ;
33import { updateJsonFile } from '../../utils/project' ;
44
5- function updateVersions ( obj : any ) {
6- const keys = Object . keys ( obj ) ;
7- keys . forEach ( key => {
8- if ( key . startsWith ( '@angular/' ) ) {
9- obj [ key ] = '2.0.0' ;
10- }
11- } ) ;
12- }
135
146export default function ( ) {
7+ let origPackageJson : string ;
158 let origCoreVersion : string ;
169 let origCliVersion : string ;
17- return updateJsonFile ( 'package.json' , obj => {
18- origCoreVersion = obj . dependencies [ '@angular/core' ] ;
19- origCliVersion = obj . devDependencies [ '@angular/cli' ] ;
20- updateVersions ( obj . dependencies ) ;
21- updateVersions ( obj . devDependencies ) ;
22- obj . devDependencies [ '@angular/cli' ] = '1.6.5' ;
23- } )
10+
11+ function updateVersions ( obj : any ) {
12+ const keys = Object . keys ( obj ) ;
13+ keys . forEach ( key => {
14+ if ( key . startsWith ( '@angular/' ) ) {
15+ obj [ key ] = '2.0.0' ;
16+ }
17+ } ) ;
18+ }
19+
20+ return readFile ( 'package.json' )
21+ . then ( ( content ) => origPackageJson = content )
22+ . then ( ( ) => updateJsonFile ( 'package.json' , obj => {
23+ origCoreVersion = obj . dependencies [ '@angular/core' ] ;
24+ origCliVersion = obj . devDependencies [ '@angular/cli' ] ;
25+ updateVersions ( obj . dependencies ) ;
26+ updateVersions ( obj . devDependencies ) ;
27+ obj . devDependencies [ '@angular/cli' ] = '1.6.5' ;
28+ } ) )
2429 . then ( ( ) => ng ( 'update' ) )
2530 . then ( ( ) => readFile ( 'package.json' ) )
2631 . then ( s => {
@@ -30,5 +35,7 @@ export default function () {
3035 if ( origCoreVersion === version || origCliVersion === cliVersion ) {
3136 throw new Error ( 'Versions not updated' ) ;
3237 }
33- } ) ;
38+ } )
39+ . then ( ( ) => writeFile ( 'package.json' , origPackageJson ) )
40+ . then ( ( ) => silentNpm ( 'install' ) ) ;
3441}
0 commit comments