You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.2 KiB

4 years ago
  1. 'use strict';
  2. const createConfig = require('./createConfig');
  3. const defaultPort = require('./defaultPort');
  4. const findPort = require('./findPort');
  5. function processOptions(config, argv, callback) {
  6. // processOptions {Promise}
  7. if (typeof config.then === 'function') {
  8. config
  9. .then((conf) => processOptions(conf, argv, callback))
  10. .catch((err) => {
  11. // eslint-disable-next-line no-console
  12. console.error(err.stack || err);
  13. // eslint-disable-next-line no-process-exit
  14. process.exit(1);
  15. });
  16. return;
  17. }
  18. // Taken out of yargs because we must know if
  19. // it wasn't given by the user, in which case
  20. // we should use portfinder.
  21. const options = createConfig(config, argv, { port: defaultPort });
  22. if (options.socket) {
  23. callback(config, options);
  24. } else {
  25. findPort(options.port)
  26. .then((port) => {
  27. options.port = port;
  28. callback(config, options);
  29. })
  30. .catch((err) => {
  31. // eslint-disable-next-line no-console
  32. console.error(err.stack || err);
  33. // eslint-disable-next-line no-process-exit
  34. process.exit(1);
  35. });
  36. }
  37. }
  38. module.exports = processOptions;