kentcdodds / nps-utils

Utilities for http://npm.im/nps (npm-package-scripts)
https://doclets.io/kentcdodds/nps-utils/master
MIT License
101 stars 23 forks source link

concurrent: options #28

Open DimitarNestorov opened 6 years ago

DimitarNestorov commented 6 years ago

Although in most cases you would want to use --kill-others-on-fail, I fell in a situation where I would prefer if it was off. Also concurrently has some other options like --no-color, --raw, and --allow-restart which I believe should be toggleable in an options object sent as a second argument to .concurrent.

kentcdodds commented 6 years ago

Hi @dimitarnestorov, I'm not really maintaining this package (or nps) anymore. I'm happy to hand these projects off to another maintainer though.

samijaber commented 6 years ago

I needed this as well to get nps-utils to play nicely with my scripts. Here's a workaround I built:

/**
 *  @type {(...additionalFlags: string[]) => (...scripts: string[]) => string}
 */
const concurrentNpsWithFlags = (...additionalFlags) => (...scripts) => {
  const [
    // this should be `node`
    nodeCall,
    // this should be the path to the `concurrently` executable
    concurrentlyExec,
    // these are all the remaining flags, along with the commands
    ...flagsAndCommands
  ] = npsUtils.concurrent.nps(...scripts).split(' ');

  return [nodeCall, concurrentlyExec, ...additionalFlags, ...flagsAndCommands].join(' ');
};

// example of usage
concurrentNpsWithFlags('--success first', '--kill-others')('command1', 'command2');

I initially wanted to raise a PR, but didn't know the best way to let concurrent.nps expose arguments for concurrently. The problem is that it expects all of its arguments to be scripts. So it'd be a breaking change to allow us to pass these flags down.