status.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. 'use strict';
  2. const open = require('opn');
  3. const colors = require('./colors');
  4. function status(uri, options, log, useColor) {
  5. const contentBase = Array.isArray(options.contentBase)
  6. ? options.contentBase.join(', ')
  7. : options.contentBase;
  8. if (options.socket) {
  9. log.info(`Listening to socket at ${colors.info(useColor, options.socket)}`);
  10. } else {
  11. log.info(`Project is running at ${colors.info(useColor, uri)}`);
  12. }
  13. log.info(
  14. `webpack output is served from ${colors.info(useColor, options.publicPath)}`
  15. );
  16. if (contentBase) {
  17. log.info(
  18. `Content not from webpack is served from ${colors.info(
  19. useColor,
  20. contentBase
  21. )}`
  22. );
  23. }
  24. if (options.historyApiFallback) {
  25. log.info(
  26. `404s will fallback to ${colors.info(
  27. useColor,
  28. options.historyApiFallback.index || '/index.html'
  29. )}`
  30. );
  31. }
  32. if (options.bonjour) {
  33. log.info(
  34. 'Broadcasting "http" with subtype of "webpack" via ZeroConf DNS (Bonjour)'
  35. );
  36. }
  37. if (options.open) {
  38. let openOptions = {};
  39. let openMessage = 'Unable to open browser';
  40. if (typeof options.open === 'string') {
  41. openOptions = { app: options.open };
  42. openMessage += `: ${options.open}`;
  43. }
  44. open(uri + (options.openPage || ''), openOptions).catch(() => {
  45. log.warn(
  46. `${openMessage}. If you are running in a headless environment, please do not use the --open flag`
  47. );
  48. });
  49. }
  50. }
  51. module.exports = status;