main.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /**
  2. * @author Toru Nagashima
  3. * @copyright 2016 Toru Nagashima. All rights reserved.
  4. * See LICENSE file in root directory for full license.
  5. */
  6. 'use strict'
  7. // ------------------------------------------------------------------------------
  8. // Requirements
  9. // ------------------------------------------------------------------------------
  10. const runAll = require('../../lib')
  11. const parseCLIArgs = require('../common/parse-cli-args')
  12. // ------------------------------------------------------------------------------
  13. // Public Interface
  14. // ------------------------------------------------------------------------------
  15. /**
  16. * Parses arguments, then run specified npm-scripts.
  17. *
  18. * @param {string[]} args - Arguments to parse.
  19. * @param {stream.Writable} stdout - A writable stream to print logs.
  20. * @param {stream.Writable} stderr - A writable stream to print errors.
  21. * @returns {Promise} A promise which comes to be fulfilled when all npm-scripts are completed.
  22. * @private
  23. */
  24. module.exports = function npmRunAll (args, stdout, stderr) {
  25. try {
  26. const stdin = process.stdin
  27. const argv = parseCLIArgs(args, { parallel: true }, { singleMode: true })
  28. const group = argv.lastGroup
  29. if (group.patterns.length === 0) {
  30. return Promise.resolve(null)
  31. }
  32. const promise = runAll(
  33. group.patterns,
  34. {
  35. stdout,
  36. stderr,
  37. stdin,
  38. parallel: group.parallel,
  39. maxParallel: argv.maxParallel,
  40. continueOnError: argv.continueOnError,
  41. printLabel: argv.printLabel,
  42. printName: argv.printName,
  43. config: argv.config,
  44. packageConfig: argv.packageConfig,
  45. silent: argv.silent,
  46. arguments: argv.rest,
  47. race: argv.race,
  48. npmPath: argv.npmPath,
  49. aggregateOutput: argv.aggregateOutput,
  50. }
  51. )
  52. if (!argv.silent) {
  53. promise.catch(err => {
  54. console.error('ERROR:', err.message)
  55. })
  56. }
  57. return promise
  58. } catch (err) {
  59. console.error('ERROR:', err.message)
  60. return Promise.reject(err)
  61. }
  62. }