1
1
const Command = require ( '../ember-cli/lib/models/command' ) ;
2
+ import { stripIndents } from 'common-tags' ;
3
+ import * as fs from 'fs' ;
2
4
import * as path from 'path' ;
3
5
import * as child_process from 'child_process' ;
4
6
import * as chalk from 'chalk' ;
@@ -11,15 +13,13 @@ const VersionCommand = Command.extend({
11
13
aliases : [ 'v' , '--version' , '-v' ] ,
12
14
works : 'everywhere' ,
13
15
14
- availableOptions : [ {
15
- name : 'verbose' ,
16
- type : Boolean ,
17
- 'default' : false ,
18
- description : 'Adds more details to output logging.'
19
- } ] ,
16
+ availableOptions : [ ] ,
20
17
21
- run : function ( options : any ) {
22
- let versions : any = process . versions ;
18
+ run : function ( _options : any ) {
19
+ let versions : { [ name : string ] : string } = { } ;
20
+ let angular : { [ name : string ] : string } = { } ;
21
+ let angularCoreVersion = '' ;
22
+ let angularSameAsCore : string [ ] = [ ] ;
23
23
const pkg = require ( path . resolve ( __dirname , '..' , 'package.json' ) ) ;
24
24
let projPkg : any ;
25
25
try {
@@ -28,10 +28,7 @@ const VersionCommand = Command.extend({
28
28
projPkg = undefined ;
29
29
}
30
30
31
- versions . os = process . platform + ' ' + process . arch ;
32
-
33
- const alwaysPrint = [ 'node' , 'os' ] ;
34
- const roots = [ '@angular/' , '@ngtools/' , 'typescript' ] ;
31
+ const roots = [ '@angular-devkit/' , '@ngtools/' , '@schematics/' , 'typescript' , 'webpack' ] ;
35
32
36
33
let ngCliVersion = pkg . version ;
37
34
if ( ! __dirname . match ( / n o d e _ m o d u l e s / ) ) {
@@ -55,31 +52,70 @@ const VersionCommand = Command.extend({
55
52
roots . forEach ( root => {
56
53
versions = Object . assign ( versions , this . getDependencyVersions ( projPkg , root ) ) ;
57
54
} ) ;
55
+ angular = this . getDependencyVersions ( projPkg , '@angular/' ) ;
56
+
57
+ // Filter all angular versions that are the same as core.
58
+ angularCoreVersion = angular [ '@angular/core' ] ;
59
+ if ( angularCoreVersion ) {
60
+ for ( const angularPackage of Object . keys ( angular ) ) {
61
+ if ( angular [ angularPackage ] == angularCoreVersion ) {
62
+ angularSameAsCore . push ( angularPackage . replace ( / ^ @ a n g u l a r \/ / , '' ) ) ;
63
+ delete angular [ angularPackage ] ;
64
+ }
65
+ }
66
+ }
58
67
}
59
- const asciiArt = ` _ _ ____ _ ___
68
+ const asciiArt = `
69
+ _ _ ____ _ ___
60
70
/ \\ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|
61
71
/ △ \\ | '_ \\ / _\` | | | | |/ _\` | '__| | | | | | |
62
72
/ ___ \\| | | | (_| | |_| | | (_| | | | |___| |___ | |
63
73
/_/ \\_\\_| |_|\\__, |\\__,_|_|\\__,_|_| \\____|_____|___|
64
- |___/` ;
65
- this . ui . writeLine ( chalk . red ( asciiArt ) ) ;
66
- this . printVersion ( '@angular/cli' , ngCliVersion ) ;
67
-
68
- for ( const module of Object . keys ( versions ) ) {
69
- const isRoot = roots . some ( root => module . startsWith ( root ) ) ;
70
- if ( options . verbose || alwaysPrint . indexOf ( module ) > - 1 || isRoot ) {
71
- this . printVersion ( module , versions [ module ] ) ;
74
+ |___/
75
+ ` ;
76
+
77
+ this . ui . writeLine ( stripIndents `
78
+ ${ chalk . red ( asciiArt ) }
79
+ Angular CLI: ${ ngCliVersion }
80
+ Node: ${ process . versions . node }
81
+ OS: ${ process . platform } ${ process . arch }
82
+ Angular: ${ angularCoreVersion }
83
+ ... ${ angularSameAsCore . sort ( ) . reduce ( ( acc , name ) => {
84
+ // Perform a simple word wrap around 60.
85
+ if ( acc . length == 0 ) {
86
+ return [ name ] ;
72
87
}
73
- }
88
+ const line = ( acc [ acc . length - 1 ] + ', ' + name ) ;
89
+ if ( line . length > 60 ) {
90
+ acc . push ( name ) ;
91
+ } else {
92
+ acc [ acc . length - 1 ] = line ;
93
+ }
94
+ return acc ;
95
+ } , [ ] ) . join ( '\n... ' ) }
96
+
97
+ ${ Object . keys ( angular ) . map ( module => module + ': ' + angular [ module ] ) . sort ( ) . join ( '\n' ) }
98
+ ${ Object . keys ( versions ) . map ( module => module + ': ' + versions [ module ] ) . sort ( ) . join ( '\n' ) }
99
+ ` ) ;
74
100
} ,
75
101
76
- getDependencyVersions : function ( pkg : any , prefix : string ) : any {
102
+ getDependencyVersions : function ( pkg : any , prefix : string ) : { [ name : string ] : string } {
77
103
const modules : any = { } ;
78
-
79
- Object . keys ( pkg [ 'dependencies' ] || { } )
104
+ const deps = Object . keys ( pkg [ 'dependencies' ] || { } )
80
105
. concat ( Object . keys ( pkg [ 'devDependencies' ] || { } ) )
81
- . filter ( depName => depName && depName . startsWith ( prefix ) )
82
- . forEach ( key => modules [ key ] = this . getVersion ( key ) ) ;
106
+ . filter ( depName => depName && depName . startsWith ( prefix ) ) ;
107
+
108
+ if ( prefix [ 0 ] == '@' ) {
109
+ try {
110
+ fs . readdirSync ( path . resolve ( this . project . root , 'node_modules' , prefix ) )
111
+ . map ( name => prefix + name )
112
+ . forEach ( name => deps . push ( name ) ) ;
113
+ } catch ( _ ) { }
114
+ } else {
115
+ modules [ prefix ] = this . getVersion ( prefix ) ;
116
+ }
117
+
118
+ deps . forEach ( name => modules [ name ] = this . getVersion ( name ) ) ;
83
119
84
120
return modules ;
85
121
} ,
@@ -95,10 +131,6 @@ const VersionCommand = Command.extend({
95
131
} catch ( e ) {
96
132
return 'error' ;
97
133
}
98
- } ,
99
-
100
- printVersion : function ( module : string , version : string ) {
101
- this . ui . writeLine ( module + ': ' + version ) ;
102
134
}
103
135
} ) ;
104
136
0 commit comments