1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.VersionCommand = void 0;
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | const core_1 = require("@angular-devkit/core");
|
12 | const fs = require("fs");
|
13 | const path = require("path");
|
14 | const command_1 = require("../models/command");
|
15 | const color_1 = require("../utilities/color");
|
16 | class VersionCommand extends command_1.Command {
|
17 | async run() {
|
18 | const cliPackage = require('../package.json');
|
19 | let workspacePackage;
|
20 | try {
|
21 | workspacePackage = require(path.resolve(this.workspace.root, 'package.json'));
|
22 | }
|
23 | catch (_a) { }
|
24 | const patterns = [
|
25 | /^@angular\/.*/,
|
26 | /^@angular-devkit\/.*/,
|
27 | /^@bazel\/.*/,
|
28 | /^@ngtools\/.*/,
|
29 | /^@nguniversal\/.*/,
|
30 | /^@schematics\/.*/,
|
31 | /^rxjs$/,
|
32 | /^typescript$/,
|
33 | /^ng-packagr$/,
|
34 | /^webpack$/,
|
35 | ];
|
36 | const packageNames = [
|
37 | ...Object.keys(cliPackage.dependencies || {}),
|
38 | ...Object.keys(cliPackage.devDependencies || {}),
|
39 | ...Object.keys((workspacePackage === null || workspacePackage === void 0 ? void 0 : workspacePackage.dependencies) || {}),
|
40 | ...Object.keys((workspacePackage === null || workspacePackage === void 0 ? void 0 : workspacePackage.devDependencies) || {}),
|
41 | ];
|
42 | const versions = packageNames
|
43 | .filter(x => patterns.some(p => p.test(x)))
|
44 | .reduce((acc, name) => {
|
45 | if (name in acc) {
|
46 | return acc;
|
47 | }
|
48 | acc[name] = this.getVersion(name);
|
49 | return acc;
|
50 | }, {});
|
51 | const ngCliVersion = cliPackage.version;
|
52 | let angularCoreVersion = '';
|
53 | const angularSameAsCore = [];
|
54 | if (workspacePackage) {
|
55 |
|
56 | angularCoreVersion = versions['@angular/core'];
|
57 | if (angularCoreVersion) {
|
58 | for (const angularPackage of Object.keys(versions)) {
|
59 | if (versions[angularPackage] == angularCoreVersion &&
|
60 | angularPackage.startsWith('@angular/')) {
|
61 | angularSameAsCore.push(angularPackage.replace(/^@angular\//, ''));
|
62 | delete versions[angularPackage];
|
63 | }
|
64 | }
|
65 |
|
66 | angularSameAsCore.sort();
|
67 | }
|
68 | }
|
69 | const namePad = ' '.repeat(Object.keys(versions).sort((a, b) => b.length - a.length)[0].length + 3);
|
70 | const asciiArt = `
|
71 | _ _ ____ _ ___
|
72 | / \\ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|
|
73 | / △ \\ | '_ \\ / _\` | | | | |/ _\` | '__| | | | | | |
|
74 | / ___ \\| | | | (_| | |_| | | (_| | | | |___| |___ | |
|
75 | /_/ \\_\\_| |_|\\__, |\\__,_|_|\\__,_|_| \\____|_____|___|
|
76 | |___/
|
77 | `
|
78 | .split('\n')
|
79 | .map(x => color_1.colors.red(x))
|
80 | .join('\n');
|
81 | this.logger.info(asciiArt);
|
82 | this.logger.info(`
|
83 | Angular CLI: ${ngCliVersion}
|
84 | Node: ${process.versions.node}
|
85 | OS: ${process.platform} ${process.arch}
|
86 |
|
87 | Angular: ${angularCoreVersion}
|
88 | ... ${angularSameAsCore
|
89 | .reduce((acc, name) => {
|
90 | // Perform a simple word wrap around 60.
|
91 | if (acc.length == 0) {
|
92 | return [name];
|
93 | }
|
94 | const line = acc[acc.length - 1] + ', ' + name;
|
95 | if (line.length > 60) {
|
96 | acc.push(name);
|
97 | }
|
98 | else {
|
99 | acc[acc.length - 1] = line;
|
100 | }
|
101 | return acc;
|
102 | }, [])
|
103 | .join('\n... ')}
|
104 | Ivy Workspace: ${workspacePackage ? this.getIvyWorkspace() : ''}
|
105 |
|
106 | Package${namePad.slice(7)}Version
|
107 | -------${namePad.replace(/ /g, '-')}------------------
|
108 | ${Object.keys(versions)
|
109 | .map(module => `${module}${namePad.slice(module.length)}${versions[module]}`)
|
110 | .sort()
|
111 | .join('\n')}
|
112 | `.replace(/^ {6}/gm, ''));
|
113 | }
|
114 | getVersion(moduleName) {
|
115 | let packagePath;
|
116 | let cliOnly = false;
|
117 |
|
118 | try {
|
119 | packagePath = require.resolve(`${moduleName}/package.json`, { paths: [this.workspace.root] });
|
120 | }
|
121 | catch (_a) { }
|
122 |
|
123 | if (!packagePath) {
|
124 | try {
|
125 | packagePath = require.resolve(`${moduleName}/package.json`);
|
126 | cliOnly = true;
|
127 | }
|
128 | catch (_b) { }
|
129 | }
|
130 | let version;
|
131 |
|
132 | if (packagePath) {
|
133 | try {
|
134 | version = require(packagePath).version + (cliOnly ? ' (cli-only)' : '');
|
135 | }
|
136 | catch (_c) { }
|
137 | }
|
138 | return version || '<error>';
|
139 | }
|
140 | getIvyWorkspace() {
|
141 | try {
|
142 | const content = fs.readFileSync(path.resolve(this.workspace.root, 'tsconfig.json'), 'utf-8');
|
143 | const tsConfig = core_1.parseJson(content, core_1.JsonParseMode.Loose);
|
144 | if (!core_1.isJsonObject(tsConfig)) {
|
145 | return '<error>';
|
146 | }
|
147 | const { angularCompilerOptions } = tsConfig;
|
148 | return core_1.isJsonObject(angularCompilerOptions) && angularCompilerOptions.enableIvy === false
|
149 | ? 'No'
|
150 | : 'Yes';
|
151 | }
|
152 | catch (_a) {
|
153 | return '<error>';
|
154 | }
|
155 | }
|
156 | }
|
157 | exports.VersionCommand = VersionCommand;
|
158 | VersionCommand.aliases = ['v'];
|