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' ;
3
3
import { updateJsonFile } from '../../utils/project' ;
4
4
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
- }
13
5
14
6
export default function ( ) {
7
+ let origPackageJson : string ;
15
8
let origCoreVersion : string ;
16
9
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
+ } ) )
24
29
. then ( ( ) => ng ( 'update' ) )
25
30
. then ( ( ) => readFile ( 'package.json' ) )
26
31
. then ( s => {
@@ -30,5 +35,7 @@ export default function () {
30
35
if ( origCoreVersion === version || origCliVersion === cliVersion ) {
31
36
throw new Error ( 'Versions not updated' ) ;
32
37
}
33
- } ) ;
38
+ } )
39
+ . then ( ( ) => writeFile ( 'package.json' , origPackageJson ) )
40
+ . then ( ( ) => silentNpm ( 'install' ) ) ;
34
41
}
0 commit comments