Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(version): display verions of @angular/* and @ngtools/* #3592

Merged
merged 1 commit into from
Dec 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because later on I have this...

versions = Object.assign(versions, this.getModules(projPkg, root));

which disallows the use of const

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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isRoot could be set to roots.some(root => module.startsWith(root)) and it would be simpler.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, cleaner

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(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you at least try locally to nom link angular itself and run ng version? Just wanna make sure that works.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested locally via npm link for both inside and outside of CLI projects.

this.project.root,
'node_modules',
moduleName,
'package.json'));
return modulePkg.version;
},

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