-
Notifications
You must be signed in to change notification settings - Fork 12k
feat(version): display verions of @angular/* and @ngtools/* #3592
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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/)) { | ||
|
@@ -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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you at least try locally to There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the change?
There was a problem hiding this comment.
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...
which disallows the use of const