UNPKG

3.68 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const Command = require('../ember-cli/lib/models/command');
4const path = require("path");
5const child_process = require("child_process");
6const chalk = require("chalk");
7const config_1 = require("../models/config");
8const VersionCommand = Command.extend({
9 name: 'version',
10 description: 'Outputs Angular CLI version.',
11 aliases: ['v', '--version', '-v'],
12 works: 'everywhere',
13 availableOptions: [{
14 name: 'verbose',
15 type: Boolean,
16 'default': false,
17 description: 'Adds more details to output logging.'
18 }],
19 run: function (options) {
20 let versions = process.versions;
21 const pkg = require(path.resolve(__dirname, '..', 'package.json'));
22 let projPkg;
23 try {
24 projPkg = require(path.resolve(this.project.root, 'package.json'));
25 }
26 catch (exception) {
27 projPkg = undefined;
28 }
29 versions.os = process.platform + ' ' + process.arch;
30 const alwaysPrint = ['node', 'os'];
31 const roots = ['@angular/', '@ngtools/'];
32 let ngCliVersion = pkg.version;
33 if (!__dirname.match(/node_modules/)) {
34 let gitBranch = '??';
35 try {
36 const gitRefName = '' + child_process.execSync('git symbolic-ref HEAD', { cwd: __dirname });
37 gitBranch = path.basename(gitRefName.replace('\n', ''));
38 }
39 catch (e) {
40 }
41 ngCliVersion = `local (v${pkg.version}, branch: ${gitBranch})`;
42 }
43 const config = config_1.CliConfig.fromProject();
44 if (config && config.config && config.config.project) {
45 if (config.config.project.ejected) {
46 ngCliVersion += ' (e)';
47 }
48 }
49 if (projPkg) {
50 roots.forEach(root => {
51 versions = Object.assign(versions, this.getDependencyVersions(projPkg, root));
52 });
53 }
54 const asciiArt = ` _ _ ____ _ ___
55 / \\ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|
56 / △ \\ | '_ \\ / _\` | | | | |/ _\` | '__| | | | | | |
57 / ___ \\| | | | (_| | |_| | | (_| | | | |___| |___ | |
58/_/ \\_\\_| |_|\\__, |\\__,_|_|\\__,_|_| \\____|_____|___|
59 |___/`;
60 this.ui.writeLine(chalk.red(asciiArt));
61 this.printVersion('@angular/cli', ngCliVersion);
62 for (const module of Object.keys(versions)) {
63 const isRoot = roots.some(root => module.startsWith(root));
64 if (options.verbose || alwaysPrint.indexOf(module) > -1 || isRoot) {
65 this.printVersion(module, versions[module]);
66 }
67 }
68 },
69 getDependencyVersions: function (pkg, prefix) {
70 const modules = {};
71 Object.keys(pkg.dependencies || {})
72 .concat(Object.keys(pkg.devDependencies || {}))
73 .filter(depName => depName && depName.startsWith(prefix))
74 .forEach(key => modules[key] = this.getVersion(key));
75 return modules;
76 },
77 getVersion: function (moduleName) {
78 try {
79 const modulePkg = require(path.resolve(this.project.root, 'node_modules', moduleName, 'package.json'));
80 return modulePkg.version;
81 }
82 catch (e) {
83 return 'error';
84 }
85 },
86 printVersion: function (module, version) {
87 this.ui.writeLine(module + ': ' + version);
88 }
89});
90VersionCommand.overrideCore = true;
91exports.default = VersionCommand;
92//# sourceMappingURL=/users/hans/sources/angular-cli/commands/version.js.map
\No newline at end of file