open-cli-tools / concurrently

Run commands concurrently. Like `npm run watch-js & npm run watch-less` but better.
https://www.npmjs.com/package/concurrently
MIT License
7k stars 228 forks source link

fix(suggestion): prefixColors API type to embrace string type #439

Closed SeiwonPark closed 11 months ago

SeiwonPark commented 1 year ago

Purpose of this PR

Regarding prefixColors's default value, and the issue #437, though the document specified as below,

a list of colors as supported by chalk or auto for an automatically picked color.

still the behavior for using API doesn't look quite neat. Here's an example:

example

// referred code from README

const concurrently = require('concurrently');
const { result } = concurrently(
  [
    'npm:watch-*',
    { command: 'nodemon', name: 'server' },
    { command: 'deploy', name: 'deploy', env: { PUBLIC_KEY: '...' } },
    {
      command: 'watch',
      name: 'watch',
      cwd: path.resolve(__dirname, 'scripts/watchers'),
    },
  ],
  {
    prefix: 'name',
    killOthers: ['failure', 'success'],
    restartTries: 3,
    cwd: path.resolve(__dirname, 'scripts'),
    prefixColors: ['auto'],     //  <--------- To use 'auto' option, it needs to be wrapped in a list
  },
);
result.then(success, failure);

and as the option is prefixColor"s", it makes sense.

But it's literally an auto so rather than wrapping it in a list,

prefixColors: 'auto' // or 'bgMagenta', 'red', 'underline', ... for other available styles

just give it a string like above might not hurt the philosophy of prefixColors's default value.

So it might be another handy option for users I guess. Or how do you think about this?


What's been updated

So I'm suggesting the string type to be able to embrace all the behaviors from users.

// src/concurrently.ts

- prefixColors?: string[];
+ prefixColors?: string | string[];


concurrently

and updated document for more details.

coveralls commented 11 months ago

Coverage Status

coverage: 99.197% (-0.1%) from 99.31% when pulling 1add5d6bb0015f1a21eb3773574e829b2931098b on SeiwonPark:fix/prefix-api-type into 16182089336827900ef2fc943b353c14b850cc9b on open-cli-tools:main.