@@ -14,12 +14,19 @@ const VersionCommand = Command.extend({
14
14
} ] ,
15
15
16
16
run : function ( options : any ) {
17
- const versions : any = process . versions ;
17
+ let versions : any = process . versions ;
18
18
const pkg = require ( path . resolve ( __dirname , '..' , 'package.json' ) ) ;
19
+ let projPkg : any ;
20
+ try {
21
+ projPkg = require ( path . resolve ( this . project . root , 'package.json' ) ) ;
22
+ } catch ( exception ) {
23
+ projPkg = undefined ;
24
+ }
19
25
20
- versions [ 'os' ] = process . platform + ' ' + process . arch ;
26
+ versions . os = process . platform + ' ' + process . arch ;
21
27
22
28
const alwaysPrint = [ 'node' , 'os' ] ;
29
+ const roots = [ '@angular/' , '@ngtools/' ] ;
23
30
24
31
let ngCliVersion = pkg . version ;
25
32
if ( ! __dirname . match ( / n o d e _ m o d u l e s / ) ) {
@@ -33,15 +40,41 @@ const VersionCommand = Command.extend({
33
40
ngCliVersion = `local (v${ pkg . version } , branch: ${ gitBranch } )` ;
34
41
}
35
42
43
+ if ( projPkg ) {
44
+ roots . forEach ( root => {
45
+ versions = Object . assign ( versions , this . getDependencyVersions ( projPkg , root ) ) ;
46
+ } ) ;
47
+ }
36
48
this . printVersion ( 'angular-cli' , ngCliVersion ) ;
37
49
38
50
for ( const module of Object . keys ( versions ) ) {
39
- if ( options . verbose || alwaysPrint . indexOf ( module ) > - 1 ) {
51
+ const isRoot = roots . some ( root => module . startsWith ( root ) ) ;
52
+ if ( options . verbose || alwaysPrint . indexOf ( module ) > - 1 || isRoot ) {
40
53
this . printVersion ( module , versions [ module ] ) ;
41
54
}
42
55
}
43
56
} ,
44
57
58
+ getDependencyVersions : function ( pkg : any , prefix : string ) : any {
59
+ const modules : any = { } ;
60
+
61
+ Object . keys ( pkg . dependencies || { } )
62
+ . concat ( Object . keys ( pkg . devDependencies || { } ) )
63
+ . filter ( depName => depName && depName . startsWith ( prefix ) )
64
+ . forEach ( key => modules [ key ] = this . getVersion ( key ) ) ;
65
+
66
+ return modules ;
67
+ } ,
68
+
69
+ getVersion : function ( moduleName : string ) : string {
70
+ const modulePkg = require ( path . resolve (
71
+ this . project . root ,
72
+ 'node_modules' ,
73
+ moduleName ,
74
+ 'package.json' ) ) ;
75
+ return modulePkg . version ;
76
+ } ,
77
+
45
78
printVersion : function ( module : string , version : string ) {
46
79
this . ui . writeLine ( module + ': ' + version ) ;
47
80
}
0 commit comments