1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.InfoCommand = void 0;
|
4 | const string_1 = require("@ionic/cli-framework/utils/string");
|
5 | const utils_terminal_1 = require("@ionic/utils-terminal");
|
6 | const lodash = require("lodash");
|
7 | const color_1 = require("../lib/color");
|
8 | const command_1 = require("../lib/command");
|
9 | const INFO_GROUPS = ['ionic', 'capacitor', 'cordova', 'utility', 'system', 'environment'];
|
10 | class InfoCommand extends command_1.Command {
|
11 | async getMetadata() {
|
12 | return {
|
13 | name: 'info',
|
14 | type: 'global',
|
15 | summary: 'Print project, system, and environment information',
|
16 | description: `
|
17 | This command is an easy way to share information about your setup. If applicable, be sure to run ${color_1.input('ionic info')} within your project directory to display even more information.
|
18 | `,
|
19 | options: [
|
20 | {
|
21 | name: 'json',
|
22 | summary: 'Print system/environment info in JSON format',
|
23 | type: Boolean,
|
24 | },
|
25 | ],
|
26 | };
|
27 | }
|
28 | async run(inputs, options) {
|
29 | const { json } = options;
|
30 | const items = (await this.env.getInfo()).filter(item => item.hidden !== true);
|
31 | if (json) {
|
32 | process.stdout.write(JSON.stringify(items));
|
33 | }
|
34 | else {
|
35 | const groupedInfo = new Map(INFO_GROUPS.map((group) => [group, items.filter(item => item.group === group)]));
|
36 | const sortInfo = (a, b) => {
|
37 | if (a.name[0] === '@' && b.name[0] !== '@') {
|
38 | return 1;
|
39 | }
|
40 | if (a.name[0] !== '@' && b.name[0] === '@') {
|
41 | return -1;
|
42 | }
|
43 | return string_1.strcmp(a.name.toLowerCase(), b.name.toLowerCase());
|
44 | };
|
45 | const projectPath = this.project && this.project.directory;
|
46 | const splitInfo = (ary) => ary
|
47 | .sort(sortInfo)
|
48 | .map((item) => [` ${item.name}${item.flair ? ' ' + color_1.weak('(' + item.flair + ')') : ''}`, color_1.weak(item.value) + (item.path && projectPath && !item.path.startsWith(projectPath) ? ` ${color_1.weak('(' + item.path + ')')}` : '')]);
|
49 | const format = (details) => utils_terminal_1.columnar(details, { vsep: ':' });
|
50 | if (!projectPath) {
|
51 | this.env.log.warn('You are not in an Ionic project directory. Project context may be missing.');
|
52 | }
|
53 | this.env.log.nl();
|
54 | for (const [group, info] of groupedInfo.entries()) {
|
55 | if (info.length > 0) {
|
56 | this.env.log.rawmsg(`${color_1.strong(`${lodash.startCase(group)}:`)}\n\n`);
|
57 | this.env.log.rawmsg(`${format(splitInfo(info))}\n\n`);
|
58 | }
|
59 | }
|
60 | }
|
61 | }
|
62 | }
|
63 | exports.InfoCommand = InfoCommand;
|