1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.CommandSchemaHelpFormatter = exports.NamespaceSchemaHelpFormatter = exports.CommandStringHelpFormatter = exports.NamespaceStringHelpFormatter = void 0;
|
4 | const cli_framework_1 = require("@ionic/cli-framework");
|
5 | const utils_array_1 = require("@ionic/utils-array");
|
6 | const color_1 = require("./color");
|
7 | const config_1 = require("./config");
|
8 | const IONIC_LOGO = String.raw `
|
9 | _ _
|
10 | (_) ___ _ __ (_) ___
|
11 | | |/ _ \| '_ \| |/ __|
|
12 | | | (_) | | | | | (__
|
13 | |_|\___/|_| |_|_|\___|`;
|
14 | class NamespaceStringHelpFormatter extends cli_framework_1.NamespaceStringHelpFormatter {
|
15 | constructor({ version, inProject, ...rest }) {
|
16 | super({ ...rest, colors: color_1.COLORS });
|
17 | this.inProject = inProject;
|
18 | this.version = version;
|
19 | }
|
20 | async formatHeader() {
|
21 | return this.namespace.parent ? super.formatHeader() : this.formatIonicHeader();
|
22 | }
|
23 | async formatIonicHeader() {
|
24 | const { strong } = this.colors;
|
25 | return `\n${IONIC_LOGO} ${strong(`CLI ${this.version}`)}\n\n`;
|
26 | }
|
27 | async getGlobalOptions() {
|
28 | const visibleOptions = await utils_array_1.filter(config_1.GLOBAL_OPTIONS, async (opt) => cli_framework_1.isOptionVisible(opt));
|
29 | return visibleOptions.map(opt => cli_framework_1.formatOptionName(opt, { colors: cli_framework_1.NO_COLORS, showAliases: false }));
|
30 | }
|
31 | async formatCommands() {
|
32 | const { strong } = this.colors;
|
33 | const commands = await this.getCommandMetadataList();
|
34 | const globalCmds = commands.filter(cmd => cmd.type === 'global');
|
35 | const projectCmds = commands.filter(cmd => cmd.type === 'project');
|
36 | return ((await this.formatCommandGroup('Global Commands', globalCmds)) +
|
37 | (this.inProject ? await this.formatCommandGroup('Project Commands', projectCmds) : `\n ${strong('Project Commands')}:\n\n You are not in a project directory.\n`));
|
38 | }
|
39 | }
|
40 | exports.NamespaceStringHelpFormatter = NamespaceStringHelpFormatter;
|
41 | class CommandStringHelpFormatter extends cli_framework_1.CommandStringHelpFormatter {
|
42 | constructor(options) {
|
43 | super({ ...options, colors: color_1.COLORS });
|
44 | }
|
45 | async formatOptions() {
|
46 | const metadata = await this.getCommandMetadata();
|
47 | const options = metadata.options ? metadata.options : [];
|
48 | const basicOptions = options.filter(o => !o.groups || !o.groups.includes("advanced" ));
|
49 | const advancedOptions = options.filter(o => o.groups && o.groups.includes("advanced" ));
|
50 | return ((await this.formatOptionsGroup('Options', basicOptions)) +
|
51 | (await this.formatOptionsGroup('Advanced Options', advancedOptions)));
|
52 | }
|
53 | async formatBeforeOptionSummary(opt) {
|
54 | return (opt.hint ? `${opt.hint} ` : '') + await super.formatBeforeOptionSummary(opt);
|
55 | }
|
56 | }
|
57 | exports.CommandStringHelpFormatter = CommandStringHelpFormatter;
|
58 | class NamespaceSchemaHelpFormatter extends cli_framework_1.NamespaceSchemaHelpFormatter {
|
59 | async formatCommand(cmd) {
|
60 | const { command } = cmd;
|
61 | const formatter = new CommandSchemaHelpFormatter({
|
62 | location: { path: [...cmd.path], obj: command, args: [] },
|
63 | command,
|
64 | metadata: cmd,
|
65 | });
|
66 | return { ...await formatter.serialize(), type: cmd.type };
|
67 | }
|
68 | }
|
69 | exports.NamespaceSchemaHelpFormatter = NamespaceSchemaHelpFormatter;
|
70 | class CommandSchemaHelpFormatter extends cli_framework_1.CommandSchemaHelpFormatter {
|
71 | async formatCommand(cmd) {
|
72 | const formatted = await super.formatCommand(cmd);
|
73 | return { ...formatted, type: cmd.type };
|
74 | }
|
75 | }
|
76 | exports.CommandSchemaHelpFormatter = CommandSchemaHelpFormatter;
|