Skip to content

Commit

Permalink
feat(help): color refactor
Browse files Browse the repository at this point in the history
BREAKING CHANGE: option/command/namespace groups are now `MetadataGroup`
  • Loading branch information
imhoffd committed Apr 17, 2019
1 parent cc1d2af commit 5938429
Show file tree
Hide file tree
Showing 55 changed files with 249 additions and 264 deletions.
9 changes: 9 additions & 0 deletions packages/@ionic/cli-framework/src/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ export interface LinkFootnote {

export type Footnote = TextFootnote | LinkFootnote;

export const enum MetadataGroup {
ADVANCED = 'advanced',
BETA = 'beta',
DEPRECATED = 'deprecated',
EXPERIMENTAL = 'experimental',
HIDDEN = 'hidden',
PAID = 'paid',
}

export interface Metadata {
name: string;
summary: string;
Expand Down
9 changes: 5 additions & 4 deletions packages/@ionic/cli-framework/src/lib/__tests__/help.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Command, CommandMap, CommandMapDefault, Namespace, NamespaceMap } from '../command';
import { CommandGroup, NamespaceGroup, OptionGroup, CommandStringHelpFormatter, NamespaceStringHelpFormatter, NamespaceSchemaHelpFormatter } from '../help';
import { CommandStringHelpFormatter, NamespaceStringHelpFormatter, NamespaceSchemaHelpFormatter } from '../help';
import { MetadataGroup } from '../../definitions';
import { stripAnsi } from '../../utils/format';

class MyNamespace extends Namespace {
Expand Down Expand Up @@ -30,7 +31,7 @@ class NamespaceWithDefault extends Namespace {
return {
name: 'defns',
summary: 'the defns namespace',
groups: [NamespaceGroup.Beta],
groups: [MetadataGroup.BETA],
};
}

Expand Down Expand Up @@ -72,7 +73,7 @@ class DefaultCommand extends Command {
return {
name: 'def',
summary: 'the default command',
groups: [CommandGroup.Beta],
groups: [MetadataGroup.BETA],
};
}

Expand All @@ -98,7 +99,7 @@ class BarCommand extends Command {
],
options: [
{ name: 'opt1', summary: 'opt1 summary', aliases: ['o'], spec: { value: 'optvalue' } },
{ name: 'opt2', summary: 'opt2 summary', groups: [OptionGroup.Advanced] },
{ name: 'opt2', summary: 'opt2 summary', groups: [MetadataGroup.ADVANCED] },
{ name: 'opt3', summary: 'opt3 summary', type: Boolean },
],
exampleCommands: ['', 'input1 input2', '--opt1 --opt2'],
Expand Down
34 changes: 33 additions & 1 deletion packages/@ionic/cli-framework/src/lib/colors.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
import chalk from 'chalk';
import * as lodash from 'lodash';

import { MetadataGroup } from '../definitions';

import { LoggerLevel } from './logger';

export type ColorFunction = (...text: string[]) => string;
export type LoggerColors = { [L in LoggerLevel]: ColorFunction; };
export type HelpGroupColors = { [G in Exclude<MetadataGroup, MetadataGroup.HIDDEN | MetadataGroup.ADVANCED>]: ColorFunction; };

export interface HelpColors {
/**
* Used to color the section titles in help output.
*/
title: ColorFunction;

group: HelpGroupColors;
}

export interface Colors {
/**
Expand Down Expand Up @@ -38,12 +50,14 @@ export interface Colors {
ancillary: ColorFunction;

log: LoggerColors;

help: HelpColors;
}

export const DEFAULT_COLORS: Colors = Object.freeze({
strong: chalk.bold,
weak: chalk.dim,
input: chalk.green,
input: chalk.cyan,
success: chalk.green,
failure: chalk.red,
ancillary: chalk.cyan,
Expand All @@ -53,6 +67,15 @@ export const DEFAULT_COLORS: Colors = Object.freeze({
WARN: chalk.yellow,
ERROR: chalk.red,
}),
help: Object.freeze({
title: chalk.bold,
group: Object.freeze({
[MetadataGroup.DEPRECATED]: chalk.yellow,
[MetadataGroup.BETA]: chalk.magenta,
[MetadataGroup.EXPERIMENTAL]: chalk.red,
[MetadataGroup.PAID]: chalk.green,
}),
}),
});

export const NO_COLORS: Colors = Object.freeze({
Expand All @@ -68,4 +91,13 @@ export const NO_COLORS: Colors = Object.freeze({
WARN: lodash.identity,
ERROR: lodash.identity,
}),
help: Object.freeze({
title: lodash.identity,
group: Object.freeze({
[MetadataGroup.DEPRECATED]: lodash.identity,
[MetadataGroup.BETA]: lodash.identity,
[MetadataGroup.EXPERIMENTAL]: lodash.identity,
[MetadataGroup.PAID]: lodash.identity,
}),
}),
});
Loading

0 comments on commit 5938429

Please sign in to comment.