@@ -14,12 +14,14 @@ 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
+ const projPkg = require ( path . resolve ( this . project . root , 'package.json' ) ) ;
19
20
20
- versions [ 'os' ] = process . platform + ' ' + process . arch ;
21
+ versions . os = process . platform + ' ' + process . arch ;
21
22
22
23
const alwaysPrint = [ 'node' , 'os' ] ;
24
+ const roots = [ '@angular/' , '@ngtools/' ] ;
23
25
24
26
let ngCliVersion = pkg . version ;
25
27
if ( ! __dirname . match ( / n o d e _ m o d u l e s / ) ) {
@@ -33,15 +35,50 @@ const VersionCommand = Command.extend({
33
35
ngCliVersion = `local (v${ pkg . version } , branch: ${ gitBranch } )` ;
34
36
}
35
37
38
+ roots . forEach ( root => {
39
+ versions = Object . assign ( versions , this . getModules ( projPkg , root ) ) ;
40
+ } )
41
+ // versions = Object.assign(versions, this.getModules(pkg, '@angular/'), this.getModules(pkg, '@ngTools/'));
42
+ // console.log(versions);
36
43
this . printVersion ( 'angular-cli' , ngCliVersion ) ;
37
44
38
45
for ( const module of Object . keys ( versions ) ) {
39
- if ( options . verbose || alwaysPrint . indexOf ( module ) > - 1 ) {
46
+ let isRoot = false ;
47
+ roots . forEach ( root => {
48
+ if ( module . startsWith ( root ) ) {
49
+ isRoot = true ;
50
+ }
51
+ } ) ;
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
+ getModules : function ( pkg : any , prefix : string ) : any {
59
+ const modules : any = { } ;
60
+ if ( pkg . dependencies ) {
61
+ for ( let key of Object . keys ( pkg . dependencies ) ) {
62
+ if ( key && key . startsWith ( prefix ) ) {
63
+ modules [ key ] = this . getVersion ( key ) ;
64
+ }
65
+ }
66
+ }
67
+ if ( pkg . devDependencies ) {
68
+ for ( let key of Object . keys ( pkg . devDependencies ) ) {
69
+ if ( key && key . startsWith ( prefix ) ) {
70
+ modules [ key ] = this . getVersion ( key ) ;
71
+ }
72
+ }
73
+ }
74
+ return modules ;
75
+ } ,
76
+
77
+ getVersion : function ( moduleName : string ) : string {
78
+ const modulePkg = require ( path . resolve ( this . project . root , 'node_modules' , moduleName , 'package.json' ) ) ;
79
+ return modulePkg . version ;
80
+ }
81
+
45
82
printVersion : function ( module : string , version : string) {
46
83
this . ui . writeLine ( module + ': ' + version ) ;
47
84
}
0 commit comments