UNPKG

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