get_console_output.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  14. exports.default = (root, verbose, buffer) => {
  15. const TITLE_INDENT = verbose ? ' ' : ' ';
  16. const CONSOLE_INDENT = TITLE_INDENT + ' ';
  17. return buffer.reduce((output, _ref) => {
  18. let type = _ref.type,
  19. message = _ref.message,
  20. origin = _ref.origin;
  21. origin = (_path || _load_path()).default.relative(root, origin);
  22. message = message.split(/\n/).map(line => CONSOLE_INDENT + line).join('\n');
  23. let typeMessage = 'console.' + type;
  24. if (type === 'warn') {
  25. message = (_chalk || _load_chalk()).default.yellow(message);
  26. typeMessage = (_chalk || _load_chalk()).default.yellow(typeMessage);
  27. } else if (type === 'error') {
  28. message = (_chalk || _load_chalk()).default.red(message);
  29. typeMessage = (_chalk || _load_chalk()).default.red(typeMessage);
  30. }
  31. return output + TITLE_INDENT + (_chalk || _load_chalk()).default.dim(typeMessage) + ' ' + (_chalk || _load_chalk()).default.dim(origin) + '\n' + message + '\n';
  32. }, '');
  33. }; /**
  34. * Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
  35. *
  36. * This source code is licensed under the MIT license found in the
  37. * LICENSE file in the root directory of this source tree.
  38. *
  39. *
  40. */