@@ -10,7 +10,7 @@ import type { Argv } from 'yargs';
1010import { CommandModule , CommandModuleImplementation } from '../../command-builder/command-module' ;
1111import { colors } from '../../utilities/color' ;
1212import { RootCommands } from '../command-config' ;
13- import { VersionInfo , gatherVersionInfo } from './version-info' ;
13+ import { gatherVersionInfo } from './version-info' ;
1414
1515/**
1616 * The Angular CLI logo, displayed as ASCII art.
@@ -65,17 +65,31 @@ export default class VersionCommandModule
6565 versions,
6666 } = versionInfo ;
6767
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' ) ;
7489
75- const angularPackages = this . formatAngularPackages ( versionInfo ) ;
7690 const packageTable = this . formatPackageTable ( versions ) ;
7791
78- logger . info ( [ ASCII_ART , header , angularPackages , packageTable ] . join ( '\n\n' ) ) ;
92+ logger . info ( [ ASCII_ART , header , packageTable ] . join ( '\n\n' ) ) ;
7993
8094 if ( unsupportedNodeVersion ) {
8195 logger . warn (
@@ -84,36 +98,6 @@ export default class VersionCommandModule
8498 }
8599 }
86100
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-
117101 /**
118102 * Formats the package table section of the version output.
119103 * @param versions A map of package names to their versions.
@@ -125,22 +109,33 @@ export default class VersionCommandModule
125109 return '' ;
126110 }
127111
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' ;
131114
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+ ) ;
134120
135121 const tableRows = versionKeys
136122 . 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 ) ;
138127
139- return `${ module } ${ padding } ${ versions [ module ] } ` ;
128+ return `│ ${ name } │ ${ coloredVersion } ${ padding } │ ` ;
140129 } )
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 ) } ─┘` ;
143138
144- return ` ${ tableHeader } \n ${ separator } \n ${ tableRows } ` ;
139+ return [ top , header , separator , ... tableRows , bottom ] . join ( '\n' ) ;
145140 }
146141}
0 commit comments