UNPKG

2.86 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const format_1 = require("@ionic/cli-framework/utils/format");
4const string_1 = require("@ionic/cli-framework/utils/string");
5const lodash = require("lodash");
6const color_1 = require("../lib/color");
7const command_1 = require("../lib/command");
8const INFO_GROUPS = ['ionic', 'capacitor', 'cordova', 'utility', 'system', 'environment'];
9class 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: `
16This 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 if (json) {
30 process.stdout.write(JSON.stringify(await this.env.getInfo()));
31 }
32 else {
33 const results = await this.env.getInfo();
34 const groupedInfo = new Map(INFO_GROUPS.map((group) => [group, results.filter(item => item.group === group)]));
35 const sortInfo = (a, b) => {
36 if (a.key[0] === '@' && b.key[0] !== '@') {
37 return 1;
38 }
39 if (a.key[0] !== '@' && b.key[0] === '@') {
40 return -1;
41 }
42 return string_1.strcmp(a.key.toLowerCase(), b.key.toLowerCase());
43 };
44 const projectPath = this.project && this.project.directory;
45 const splitInfo = (ary) => ary
46 .sort(sortInfo)
47 .map((item) => [` ${item.key}${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}
62exports.InfoCommand = InfoCommand;