From 81529a97be1d5fb3577004bf538af43c97b5b164 Mon Sep 17 00:00:00 2001 From: SeiwonPark <63793178+SeiwonPark@users.noreply.github.com> Date: Sun, 24 Sep 2023 05:25:57 +0900 Subject: [PATCH] fix(suggestion): prefixColors API type to embrace string type (#439) --- README.md | 2 +- src/concurrently.ts | 17 +++++++++++++++-- src/prefix-color-selector.ts | 5 +++-- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 814e6551..1f92edd9 100644 --- a/README.md +++ b/README.md @@ -335,7 +335,7 @@ For more details, visit https://github.com/open-cli-tools/concurrently - `prefix`: the prefix type to use when logging processes output. Possible values: `index`, `pid`, `time`, `command`, `name`, `none`, or a template (eg `[{time} process: {pid}]`). Default: the name of the process, or its index if no name is set. - - `prefixColors`: a list of colors as supported by [chalk](https://www.npmjs.com/package/chalk) or `auto` for an automatically picked color. + - `prefixColors`: a list of colors or a string as supported by [chalk](https://www.npmjs.com/package/chalk) and additional style `auto` for an automatically picked color. If concurrently would run more commands than there are colors, the last color is repeated, unless if the last color value is `auto` which means following colors are automatically picked to vary. Prefix colors specified per-command take precedence over this list. - `prefixLength`: how many characters to show when prefixing with `command`. Default: `10` diff --git a/src/concurrently.ts b/src/concurrently.ts index ad3f8f7d..2c5b9ec8 100644 --- a/src/concurrently.ts +++ b/src/concurrently.ts @@ -62,9 +62,22 @@ export type ConcurrentlyOptions = { group?: boolean; /** - * Comma-separated list of chalk colors to use on prefixes. + * A comma-separated list of chalk colors or a string for available styles listed below to use on prefixes. + * If there are more commands than colors, the last color will be repeated. + * + * Available modifiers: + * - `reset`, `bold`, `dim`, `italic`, `underline`, `inverse`, `hidden`, `strikethrough` + * + * Available colors: + * - `black`, `red`, `green`, `yellow`, `blue`, `magenta`, `cyan`, `white`, `gray`, + * any hex values for colors (e.g. `#23de43`) or `auto` for an automatically picked color + * + * Available background colors: + * - `bgBlack`, `bgRed`, `bgGreen`, `bgYellow`, `bgBlue`, `bgMagenta`, `bgCyan`, `bgWhite` + * + * @see {@link https://www.npmjs.com/package/chalk} for more information. */ - prefixColors?: string[]; + prefixColors?: string | string[]; /** * Maximum number of commands to run at once. diff --git a/src/prefix-color-selector.ts b/src/prefix-color-selector.ts index 092b5e02..63ae0727 100644 --- a/src/prefix-color-selector.ts +++ b/src/prefix-color-selector.ts @@ -58,8 +58,9 @@ function* createColorGenerator(customColors: string[]): Generator; - constructor(customColors: string[] = []) { - this.colorGenerator = createColorGenerator(customColors); + constructor(customColors: string | string[] = []) { + const normalizedColors = typeof customColors === 'string' ? [customColors] : customColors; + this.colorGenerator = createColorGenerator(normalizedColors); } /** A list of colors that are readable in a terminal. */