get_console_output.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', {
  3. value: true
  4. });
  5. var _path;
  6. function _load_path() {
  7. return (_path = _interopRequireDefault(require('path')));
  8. }
  9. var _chalk;
  10. function _load_chalk() {
  11. return (_chalk = _interopRequireDefault(require('chalk')));
  12. }
  13. var _slash;
  14. function _load_slash() {
  15. return (_slash = _interopRequireDefault(require('slash')));
  16. }
  17. function _interopRequireDefault(obj) {
  18. return obj && obj.__esModule ? obj : {default: obj};
  19. }
  20. /**
  21. * Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
  22. *
  23. * This source code is licensed under the MIT license found in the
  24. * LICENSE file in the root directory of this source tree.
  25. *
  26. *
  27. */
  28. exports.default = (root, verbose, buffer) => {
  29. const TITLE_INDENT = verbose ? ' ' : ' ';
  30. const CONSOLE_INDENT = TITLE_INDENT + ' ';
  31. return buffer.reduce((output, _ref) => {
  32. let type = _ref.type,
  33. message = _ref.message,
  34. origin = _ref.origin;
  35. origin = (0, (_slash || _load_slash()).default)(
  36. (_path || _load_path()).default.relative(root, origin)
  37. );
  38. message = message
  39. .split(/\n/)
  40. .map(line => CONSOLE_INDENT + line)
  41. .join('\n');
  42. let typeMessage = 'console.' + type;
  43. if (type === 'warn') {
  44. message = (_chalk || _load_chalk()).default.yellow(message);
  45. typeMessage = (_chalk || _load_chalk()).default.yellow(typeMessage);
  46. } else if (type === 'error') {
  47. message = (_chalk || _load_chalk()).default.red(message);
  48. typeMessage = (_chalk || _load_chalk()).default.red(typeMessage);
  49. }
  50. return (
  51. output +
  52. TITLE_INDENT +
  53. (_chalk || _load_chalk()).default.dim(typeMessage) +
  54. ' ' +
  55. (_chalk || _load_chalk()).default.dim(origin) +
  56. '\n' +
  57. message +
  58. '\n'
  59. );
  60. }, '');
  61. };