bootstrap.js 1.4 KB

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