main.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /**
  2. * @author Toru Nagashima
  3. * @copyright 2015 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)
  28. const promise = argv.groups.reduce(
  29. (prev, group) => {
  30. if (group.patterns.length === 0) {
  31. return prev
  32. }
  33. return prev.then(() => runAll(
  34. group.patterns,
  35. {
  36. stdout,
  37. stderr,
  38. stdin,
  39. parallel: group.parallel,
  40. maxParallel: group.parallel ? argv.maxParallel : 1,
  41. continueOnError: argv.continueOnError,
  42. printLabel: argv.printLabel,
  43. printName: argv.printName,
  44. config: argv.config,
  45. packageConfig: argv.packageConfig,
  46. silent: argv.silent,
  47. arguments: argv.rest,
  48. race: group.parallel && argv.race,
  49. npmPath: argv.npmPath,
  50. aggregateOutput: group.parallel && argv.aggregateOutput,
  51. }
  52. ))
  53. },
  54. Promise.resolve(null)
  55. )
  56. if (!argv.silent) {
  57. promise.catch(err => {
  58. console.error('ERROR:', err.message)
  59. })
  60. }
  61. return promise
  62. } catch (err) {
  63. console.error('ERROR:', err.message)
  64. return Promise.reject(err)
  65. }
  66. }