Skip to content

Commit 560e3ea

Browse files
committed
feat(version): display verions of @angular/* and @ngtools/*
Fixes #3589
1 parent e9bc887 commit 560e3ea

File tree

1 file changed

+40
-3
lines changed

1 file changed

+40
-3
lines changed

packages/angular-cli/commands/version.ts

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@ const VersionCommand = Command.extend({
1414
}],
1515

1616
run: function (options: any) {
17-
const versions: any = process.versions;
17+
let versions: any = process.versions;
1818
const pkg = require(path.resolve(__dirname, '..', 'package.json'));
19+
const projPkg = require(path.resolve(this.project.root, 'package.json'));
1920

20-
versions['os'] = process.platform + ' ' + process.arch;
21+
versions.os = process.platform + ' ' + process.arch;
2122

2223
const alwaysPrint = ['node', 'os'];
24+
const roots = ['@angular/', '@ngtools/'];
2325

2426
let ngCliVersion = pkg.version;
2527
if (!__dirname.match(/node_modules/)) {
@@ -33,15 +35,50 @@ const VersionCommand = Command.extend({
3335
ngCliVersion = `local (v${pkg.version}, branch: ${gitBranch})`;
3436
}
3537

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);
3643
this.printVersion('angular-cli', ngCliVersion);
3744

3845
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) {
4053
this.printVersion(module, versions[module]);
4154
}
4255
}
4356
},
4457

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+
4582
printVersion: function (module: string, version: string) {
4683
this.ui.writeLine(module + ': ' + version);
4784
}

0 commit comments

Comments
 (0)