index.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. const LogTimings = require( './src/flow-control/log-timings' );
  11. module.exports = exports = (commands, options = {}) => {
  12. const logger = new Logger({
  13. hide: options.hide,
  14. outputStream: options.outputStream || process.stdout,
  15. prefixFormat: options.prefix,
  16. prefixLength: options.prefixLength,
  17. raw: options.raw,
  18. timestampFormat: options.timestampFormat,
  19. });
  20. return concurrently(commands, {
  21. maxProcesses: options.maxProcesses,
  22. raw: options.raw,
  23. successCondition: options.successCondition,
  24. cwd: options.cwd,
  25. controllers: [
  26. new LogError({ logger }),
  27. new LogOutput({ logger }),
  28. new LogExit({ logger }),
  29. new InputHandler({
  30. logger,
  31. defaultInputTarget: options.defaultInputTarget,
  32. inputStream: options.inputStream || (options.handleInput && process.stdin),
  33. pauseInputStreamOnFinish: options.pauseInputStreamOnFinish,
  34. }),
  35. new KillOnSignal({ process }),
  36. new RestartProcess({
  37. logger,
  38. delay: options.restartDelay,
  39. tries: options.restartTries,
  40. }),
  41. new KillOthers({
  42. logger,
  43. conditions: options.killOthers
  44. }),
  45. new LogTimings({
  46. logger: options.timings ? logger: null,
  47. timestampFormat: options.timestampFormat,
  48. })
  49. ],
  50. prefixColors: options.prefixColors || [],
  51. timings: options.timings
  52. });
  53. };
  54. // Export all flow controllers and the main concurrently function,
  55. // so that 3rd-parties can use them however they want
  56. exports.concurrently = concurrently;
  57. exports.Logger = Logger;
  58. exports.InputHandler = InputHandler;
  59. exports.KillOnSignal = KillOnSignal;
  60. exports.KillOthers = KillOthers;
  61. exports.LogError = LogError;
  62. exports.LogExit = LogExit;
  63. exports.LogOutput = LogOutput;
  64. exports.RestartProcess = RestartProcess;
  65. exports.LogTimings = LogTimings;