bootstrap.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. // Public Interface
  9. // ------------------------------------------------------------------------------
  10. module.exports = function bootstrap (name) {
  11. const argv = process.argv.slice(2)
  12. switch (argv[0]) {
  13. case undefined:
  14. case '-h':
  15. case '--help':
  16. return require(`../${name}/help`)(process.stdout)
  17. case '-v':
  18. case '--version':
  19. return require('./version')(process.stdout)
  20. default:
  21. // https://github.com/mysticatea/npm-run-all/issues/105
  22. // Avoid MaxListenersExceededWarnings.
  23. process.stdout.setMaxListeners(0)
  24. process.stderr.setMaxListeners(0)
  25. process.stdin.setMaxListeners(0)
  26. // Main
  27. return require(`../${name}/main`)(
  28. argv,
  29. process.stdout,
  30. process.stderr
  31. ).then(
  32. () => {
  33. // I'm not sure why, but maybe the process never exits
  34. // on Git Bash (MINGW64)
  35. process.exit(0)
  36. },
  37. () => {
  38. process.exit(1)
  39. }
  40. )
  41. }
  42. }