main.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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: false }, { 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. continueOnError: argv.continueOnError,
  40. printLabel: argv.printLabel,
  41. printName: argv.printName,
  42. config: argv.config,
  43. packageConfig: argv.packageConfig,
  44. silent: argv.silent,
  45. arguments: argv.rest,
  46. npmPath: argv.npmPath,
  47. }
  48. )
  49. if (!argv.silent) {
  50. promise.catch(err => {
  51. console.error('ERROR:', err.message)
  52. })
  53. }
  54. return promise
  55. } catch (err) {
  56. console.error('ERROR:', err.message)
  57. return Promise.reject(err)
  58. }
  59. }