Skip to content

Commit 6386633

Browse files
committed
feat(@angular/cli): show more version information
Group all Angular packages that have the same version as @angular/core, and also show information for schematics, devkit and others that might not be in the package.json but still installed. Those versions are important.
1 parent eac1825 commit 6386633

File tree

1 file changed

+63
-31
lines changed

1 file changed

+63
-31
lines changed

packages/@angular/cli/commands/version.ts

Lines changed: 63 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
const Command = require('../ember-cli/lib/models/command');
2+
import { stripIndents } from 'common-tags';
3+
import * as fs from 'fs';
24
import * as path from 'path';
35
import * as child_process from 'child_process';
46
import * as chalk from 'chalk';
@@ -11,15 +13,13 @@ const VersionCommand = Command.extend({
1113
aliases: ['v', '--version', '-v'],
1214
works: 'everywhere',
1315

14-
availableOptions: [{
15-
name: 'verbose',
16-
type: Boolean,
17-
'default': false,
18-
description: 'Adds more details to output logging.'
19-
}],
16+
availableOptions: [],
2017

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[] = [];
2323
const pkg = require(path.resolve(__dirname, '..', 'package.json'));
2424
let projPkg: any;
2525
try {
@@ -28,10 +28,7 @@ const VersionCommand = Command.extend({
2828
projPkg = undefined;
2929
}
3030

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'];
3532

3633
let ngCliVersion = pkg.version;
3734
if (!__dirname.match(/node_modules/)) {
@@ -55,31 +52,70 @@ const VersionCommand = Command.extend({
5552
roots.forEach(root => {
5653
versions = Object.assign(versions, this.getDependencyVersions(projPkg, root));
5754
});
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(/^@angular\//, ''));
63+
delete angular[angularPackage];
64+
}
65+
}
66+
}
5867
}
59-
const asciiArt = ` _ _ ____ _ ___
68+
const asciiArt = `
69+
_ _ ____ _ ___
6070
/ \\ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|
6171
/ △ \\ | '_ \\ / _\` | | | | |/ _\` | '__| | | | | | |
6272
/ ___ \\| | | | (_| | |_| | | (_| | | | |___| |___ | |
6373
/_/ \\_\\_| |_|\\__, |\\__,_|_|\\__,_|_| \\____|_____|___|
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];
7287
}
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+
`);
74100
},
75101

76-
getDependencyVersions: function(pkg: any, prefix: string): any {
102+
getDependencyVersions: function(pkg: any, prefix: string): { [name: string]: string } {
77103
const modules: any = {};
78-
79-
Object.keys(pkg['dependencies'] || {})
104+
const deps = Object.keys(pkg['dependencies'] || {})
80105
.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));
83119

84120
return modules;
85121
},
@@ -95,10 +131,6 @@ const VersionCommand = Command.extend({
95131
} catch (e) {
96132
return 'error';
97133
}
98-
},
99-
100-
printVersion: function (module: string, version: string) {
101-
this.ui.writeLine(module + ': ' + version);
102134
}
103135
});
104136

0 commit comments

Comments
 (0)