Skip to content

Commit

Permalink
feat(version): display verions of @angular/* and @ngtools/* (#3592)
Browse files Browse the repository at this point in the history
Fixes #3589
  • Loading branch information
Brocco authored and hansl committed Dec 19, 2016
1 parent 8e9abf9 commit 123f74d
Show file tree
Hide file tree
Showing 2 changed files with 6,207 additions and 3 deletions.
39 changes: 36 additions & 3 deletions packages/angular-cli/commands/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,19 @@ const VersionCommand = Command.extend({
}],

run: function (options: any) {
const versions: any = process.versions;
let versions: any = process.versions;
const pkg = require(path.resolve(__dirname, '..', 'package.json'));
let projPkg: any;
try {
projPkg = require(path.resolve(this.project.root, 'package.json'));
} catch (exception) {
projPkg = undefined;
}

versions['os'] = process.platform + ' ' + process.arch;
versions.os = process.platform + ' ' + process.arch;

const alwaysPrint = ['node', 'os'];
const roots = ['@angular/', '@ngtools/'];

let ngCliVersion = pkg.version;
if (!__dirname.match(/node_modules/)) {
Expand All @@ -33,15 +40,41 @@ const VersionCommand = Command.extend({
ngCliVersion = `local (v${pkg.version}, branch: ${gitBranch})`;
}

if (projPkg) {
roots.forEach(root => {
versions = Object.assign(versions, this.getDependencyVersions(projPkg, root));
});
}
this.printVersion('angular-cli', ngCliVersion);

for (const module of Object.keys(versions)) {
if (options.verbose || alwaysPrint.indexOf(module) > -1) {
const isRoot = roots.some(root => module.startsWith(root));
if (options.verbose || alwaysPrint.indexOf(module) > -1 || isRoot) {
this.printVersion(module, versions[module]);
}
}
},

getDependencyVersions: function(pkg: any, prefix: string): any {
const modules: any = {};

Object.keys(pkg.dependencies || {})
.concat(Object.keys(pkg.devDependencies || {}))
.filter(depName => depName && depName.startsWith(prefix))
.forEach(key => modules[key] = this.getVersion(key));

return modules;
},

getVersion: function(moduleName: string): string {
const modulePkg = require(path.resolve(
this.project.root,
'node_modules',
moduleName,
'package.json'));
return modulePkg.version;
},

printVersion: function (module: string, version: string) {
this.ui.writeLine(module + ': ' + version);
}
Expand Down
Loading

0 comments on commit 123f74d

Please sign in to comment.