index.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. const InputHandler = require('./src/flow-control/input-handler');
  2. const KillOnSignal = require('./src/flow-control/kill-on-signal');
  3. const KillOthers = require('./src/flow-control/kill-others');
  4. const LogError = require('./src/flow-control/log-error');
  5. const LogExit = require('./src/flow-control/log-exit');
  6. const LogOutput = require('./src/flow-control/log-output');
  7. const RestartProcess = require('./src/flow-control/restart-process');
  8. const concurrently = require('./src/concurrently');
  9. const Logger = require('./src/logger');
  10. module.exports = (commands, options = {}) => {
  11. const logger = new Logger({
  12. outputStream: options.outputStream || process.stdout,
  13. prefixFormat: options.prefix,
  14. prefixLength: options.prefixLength,
  15. raw: options.raw,
  16. timestampFormat: options.timestampFormat,
  17. });
  18. return concurrently(commands, {
  19. maxProcesses: options.maxProcesses,
  20. raw: options.raw,
  21. successCondition: options.successCondition,
  22. cwd: options.cwd,
  23. controllers: [
  24. new LogError({ logger }),
  25. new LogOutput({ logger }),
  26. new LogExit({ logger }),
  27. new InputHandler({
  28. logger,
  29. defaultInputTarget: options.defaultInputTarget,
  30. inputStream: options.inputStream,
  31. }),
  32. new KillOnSignal({ process }),
  33. new RestartProcess({
  34. logger,
  35. delay: options.restartDelay,
  36. tries: options.restartTries,
  37. }),
  38. new KillOthers({
  39. logger,
  40. conditions: options.killOthers
  41. })
  42. ]
  43. });
  44. };
  45. // Export all flow controllers and the main concurrently function,
  46. // so that 3rd-parties can use them however they want
  47. exports.concurrently = concurrently;
  48. exports.Logger = Logger;
  49. exports.InputHandler = InputHandler;
  50. exports.KillOnSignal = KillOnSignal;
  51. exports.KillOthers = KillOthers;
  52. exports.LogError = LogError;
  53. exports.LogExit = LogExit;
  54. exports.LogOutput = LogOutput;
  55. exports.RestartProcess = RestartProcess;