info.js 2.9 KB

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