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