| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- /**
- * @license
- * Copyright Google Inc. All Rights Reserved.
- *
- * Use of this source code is governed by an MIT-style license that can be
- * found in the LICENSE file at https://angular.io/license
- */
- const child_process = require("child_process");
- const fs = require("fs");
- const path = require("path");
- const command_1 = require("../models/command");
- const color_1 = require("../utilities/color");
- const find_up_1 = require("../utilities/find-up");
- class VersionCommand extends command_1.Command {
- async run() {
- const pkg = require(path.resolve(__dirname, '..', 'package.json'));
- let projPkg;
- try {
- projPkg = require(path.resolve(this.workspace.root, 'package.json'));
- }
- catch (exception) {
- projPkg = undefined;
- }
- const patterns = [
- /^@angular\/.*/,
- /^@angular-devkit\/.*/,
- /^@bazel\/.*/,
- /^@ngtools\/.*/,
- /^@nguniversal\/.*/,
- /^@schematics\/.*/,
- /^rxjs$/,
- /^typescript$/,
- /^ng-packagr$/,
- /^webpack$/,
- ];
- const maybeNodeModules = find_up_1.findUp('node_modules', __dirname);
- const packageRoot = projPkg
- ? path.resolve(this.workspace.root, 'node_modules')
- : maybeNodeModules;
- const packageNames = [
- ...Object.keys((pkg && pkg['dependencies']) || {}),
- ...Object.keys((pkg && pkg['devDependencies']) || {}),
- ...Object.keys((projPkg && projPkg['dependencies']) || {}),
- ...Object.keys((projPkg && projPkg['devDependencies']) || {}),
- ];
- if (packageRoot != null) {
- // Add all node_modules and node_modules/@*/*
- const nodePackageNames = fs.readdirSync(packageRoot).reduce((acc, name) => {
- if (name.startsWith('@')) {
- return acc.concat(fs.readdirSync(path.resolve(packageRoot, name)).map(subName => name + '/' + subName));
- }
- else {
- return acc.concat(name);
- }
- }, []);
- packageNames.push(...nodePackageNames);
- }
- const versions = packageNames
- .filter(x => patterns.some(p => p.test(x)))
- .reduce((acc, name) => {
- if (name in acc) {
- return acc;
- }
- acc[name] = this.getVersion(name, packageRoot, maybeNodeModules);
- return acc;
- }, {});
- let ngCliVersion = pkg.version;
- if (!__dirname.match(/node_modules/)) {
- let gitBranch = '??';
- try {
- const gitRefName = child_process.execSync('git rev-parse --abbrev-ref HEAD', {
- cwd: __dirname,
- encoding: 'utf8',
- stdio: 'pipe',
- });
- gitBranch = gitRefName.replace('\n', '');
- }
- catch (_a) { }
- ngCliVersion = `local (v${pkg.version}, branch: ${gitBranch})`;
- }
- let angularCoreVersion = '';
- const angularSameAsCore = [];
- if (projPkg) {
- // Filter all angular versions that are the same as core.
- angularCoreVersion = versions['@angular/core'];
- if (angularCoreVersion) {
- for (const angularPackage of Object.keys(versions)) {
- if (versions[angularPackage] == angularCoreVersion &&
- angularPackage.startsWith('@angular/')) {
- angularSameAsCore.push(angularPackage.replace(/^@angular\//, ''));
- delete versions[angularPackage];
- }
- }
- // Make sure we list them in alphabetical order.
- angularSameAsCore.sort();
- }
- }
- const namePad = ' '.repeat(Object.keys(versions).sort((a, b) => b.length - a.length)[0].length + 3);
- const asciiArt = `
- _ _ ____ _ ___
- / \\ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|
- / △ \\ | '_ \\ / _\` | | | | |/ _\` | '__| | | | | | |
- / ___ \\| | | | (_| | |_| | | (_| | | | |___| |___ | |
- /_/ \\_\\_| |_|\\__, |\\__,_|_|\\__,_|_| \\____|_____|___|
- |___/
- `
- .split('\n')
- .map(x => color_1.colors.red(x))
- .join('\n');
- this.logger.info(asciiArt);
- this.logger.info(`
- Angular CLI: ${ngCliVersion}
- Node: ${process.versions.node}
- OS: ${process.platform} ${process.arch}
- Angular: ${angularCoreVersion}
- ... ${angularSameAsCore
- .reduce((acc, name) => {
- // Perform a simple word wrap around 60.
- if (acc.length == 0) {
- return [name];
- }
- const line = acc[acc.length - 1] + ', ' + name;
- if (line.length > 60) {
- acc.push(name);
- }
- else {
- acc[acc.length - 1] = line;
- }
- return acc;
- }, [])
- .join('\n... ')}
- Package${namePad.slice(7)}Version
- -------${namePad.replace(/ /g, '-')}------------------
- ${Object.keys(versions)
- .map(module => `${module}${namePad.slice(module.length)}${versions[module]}`)
- .sort()
- .join('\n')}
- `.replace(/^ {6}/gm, ''));
- }
- getVersion(moduleName, projectNodeModules, cliNodeModules) {
- try {
- if (projectNodeModules) {
- const modulePkg = require(path.resolve(projectNodeModules, moduleName, 'package.json'));
- return modulePkg.version;
- }
- }
- catch (_) { }
- try {
- if (cliNodeModules) {
- const modulePkg = require(path.resolve(cliNodeModules, moduleName, 'package.json'));
- return modulePkg.version + ' (cli-only)';
- }
- }
- catch (_a) { }
- return '<error>';
- }
- }
- VersionCommand.aliases = ['v'];
- exports.VersionCommand = VersionCommand;
|