@@ -10,7 +10,7 @@ import type { Argv } from 'yargs';
10
10
import { CommandModule , CommandModuleImplementation } from '../../command-builder/command-module' ;
11
11
import { colors } from '../../utilities/color' ;
12
12
import { RootCommands } from '../command-config' ;
13
- import { VersionInfo , gatherVersionInfo } from './version-info' ;
13
+ import { gatherVersionInfo } from './version-info' ;
14
14
15
15
/**
16
16
* The Angular CLI logo, displayed as ASCII art.
@@ -65,17 +65,31 @@ export default class VersionCommandModule
65
65
versions,
66
66
} = versionInfo ;
67
67
68
- const header = `
69
- Angular CLI: ${ ngCliVersion }
70
- Node: ${ nodeVersion } ${ unsupportedNodeVersion ? ' (Unsupported)' : '' }
71
- Package Manager: ${ packageManagerName } ${ packageManagerVersion ?? '<error>' }
72
- OS: ${ os } ${ arch }
73
- ` . replace ( / ^ { 6 } / gm, '' ) ;
68
+ const headerInfo = [
69
+ { label : 'Angular CLI' , value : ngCliVersion } ,
70
+ {
71
+ label : 'Node.js' ,
72
+ value : `${ nodeVersion } ${ unsupportedNodeVersion ? colors . yellow ( ' (Unsupported)' ) : '' } ` ,
73
+ } ,
74
+ {
75
+ label : 'Package Manager' ,
76
+ value : `${ packageManagerName } ${ packageManagerVersion ?? '<error>' } ` ,
77
+ } ,
78
+ { label : 'Operating System' , value : `${ os } ${ arch } ` } ,
79
+ ] ;
80
+
81
+ const maxHeaderLabelLength = Math . max ( ...headerInfo . map ( ( l ) => l . label . length ) ) ;
82
+
83
+ const header = headerInfo
84
+ . map (
85
+ ( { label, value } ) =>
86
+ colors . bold ( label . padEnd ( maxHeaderLabelLength + 2 ) ) + `: ${ colors . cyan ( value ) } ` ,
87
+ )
88
+ . join ( '\n' ) ;
74
89
75
- const angularPackages = this . formatAngularPackages ( versionInfo ) ;
76
90
const packageTable = this . formatPackageTable ( versions ) ;
77
91
78
- logger . info ( [ ASCII_ART , header , angularPackages , packageTable ] . join ( '\n\n' ) ) ;
92
+ logger . info ( [ ASCII_ART , header , packageTable ] . join ( '\n\n' ) ) ;
79
93
80
94
if ( unsupportedNodeVersion ) {
81
95
logger . warn (
@@ -84,36 +98,6 @@ export default class VersionCommandModule
84
98
}
85
99
}
86
100
87
- /**
88
- * Formats the Angular packages section of the version output.
89
- * @param versionInfo An object containing the version information.
90
- * @returns A string containing the formatted Angular packages information.
91
- */
92
- private formatAngularPackages ( versionInfo : VersionInfo ) : string {
93
- const { angularCoreVersion, angularSameAsCore } = versionInfo ;
94
- if ( ! angularCoreVersion ) {
95
- return 'Angular: <error>' ;
96
- }
97
-
98
- const wrappedPackages = angularSameAsCore
99
- . reduce < string [ ] > ( ( acc , name ) => {
100
- if ( acc . length === 0 ) {
101
- return [ name ] ;
102
- }
103
- const line = acc [ acc . length - 1 ] + ', ' + name ;
104
- if ( line . length > 60 ) {
105
- acc . push ( name ) ;
106
- } else {
107
- acc [ acc . length - 1 ] = line ;
108
- }
109
-
110
- return acc ;
111
- } , [ ] )
112
- . join ( '\n... ' ) ;
113
-
114
- return `Angular: ${ angularCoreVersion } \n... ${ wrappedPackages } ` ;
115
- }
116
-
117
101
/**
118
102
* Formats the package table section of the version output.
119
103
* @param versions A map of package names to their versions.
@@ -125,22 +109,33 @@ export default class VersionCommandModule
125
109
return '' ;
126
110
}
127
111
128
- const header = 'Package' ;
129
- const maxNameLength = Math . max ( ...versionKeys . map ( ( key ) => key . length ) ) ;
130
- const namePad = ' ' . repeat ( Math . max ( 0 , maxNameLength - header . length ) + 3 ) ;
112
+ const nameHeader = 'Package' ;
113
+ const versionHeader = 'Version' ;
131
114
132
- const tableHeader = `${ header } ${ namePad } Version` ;
133
- const separator = '-' . repeat ( tableHeader . length ) ;
115
+ const maxNameLength = Math . max ( nameHeader . length , ...versionKeys . map ( ( key ) => key . length ) ) ;
116
+ const maxVersionLength = Math . max (
117
+ versionHeader . length ,
118
+ ...versionKeys . map ( ( key ) => versions [ key ] . length ) ,
119
+ ) ;
134
120
135
121
const tableRows = versionKeys
136
122
. map ( ( module ) => {
137
- const padding = ' ' . repeat ( maxNameLength - module . length + 3 ) ;
123
+ const name = module . padEnd ( maxNameLength ) ;
124
+ const version = versions [ module ] ;
125
+ const coloredVersion = version === '<error>' ? colors . red ( version ) : colors . cyan ( version ) ;
126
+ const padding = ' ' . repeat ( maxVersionLength - version . length ) ;
138
127
139
- return `${ module } ${ padding } ${ versions [ module ] } ` ;
128
+ return `│ ${ name } │ ${ coloredVersion } ${ padding } │ ` ;
140
129
} )
141
- . sort ( )
142
- . join ( '\n' ) ;
130
+ . sort ( ) ;
131
+
132
+ const top = `┌─${ '─' . repeat ( maxNameLength ) } ─┬─${ '─' . repeat ( maxVersionLength ) } ─┐` ;
133
+ const header = `│ ${ nameHeader . padEnd ( maxNameLength ) } │ ${ versionHeader . padEnd (
134
+ maxVersionLength ,
135
+ ) } │`;
136
+ const separator = `├─${ '─' . repeat ( maxNameLength ) } ─┼─${ '─' . repeat ( maxVersionLength ) } ─┤` ;
137
+ const bottom = `└─${ '─' . repeat ( maxNameLength ) } ─┴─${ '─' . repeat ( maxVersionLength ) } ─┘` ;
143
138
144
- return ` ${ tableHeader } \n ${ separator } \n ${ tableRows } ` ;
139
+ return [ top , header , separator , ... tableRows , bottom ] . join ( '\n' ) ;
145
140
}
146
141
}
0 commit comments