@@ -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,54 @@ 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 . getModules ( 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
+ let isRoot = false ;
52
+ roots . forEach ( root => {
53
+ if ( module . startsWith ( root ) ) {
54
+ isRoot = true ;
55
+ }
56
+ } ) ;
57
+ if ( options . verbose || alwaysPrint . indexOf ( module ) > - 1 || isRoot ) {
40
58
this . printVersion ( module , versions [ module ] ) ;
41
59
}
42
60
}
43
61
} ,
44
62
63
+ getModules : function ( pkg : any , prefix : string ) : any {
64
+ const modules : any = { } ;
65
+ if ( pkg . dependencies ) {
66
+ for ( let key of Object . keys ( pkg . dependencies ) ) {
67
+ if ( key && key . startsWith ( prefix ) ) {
68
+ modules [ key ] = this . getVersion ( key ) ;
69
+ }
70
+ }
71
+ }
72
+ if ( pkg . devDependencies ) {
73
+ for ( let key of Object . keys ( pkg . devDependencies ) ) {
74
+ if ( key && key . startsWith ( prefix ) ) {
75
+ modules [ key ] = this . getVersion ( key ) ;
76
+ }
77
+ }
78
+ }
79
+ return modules ;
80
+ } ,
81
+
82
+ getVersion : function ( moduleName : string ) : string {
83
+ const modulePkg = require ( path . resolve (
84
+ this . project . root ,
85
+ 'node_modules' ,
86
+ moduleName ,
87
+ 'package.json' ) ) ;
88
+ return modulePkg . version ;
89
+ } ,
90
+
45
91
printVersion : function ( module : string , version : string ) {
46
92
this . ui . writeLine ( module + ': ' + version ) ;
47
93
}
0 commit comments