UNPKG

1.76 kBJavaScriptView Raw
1/**
2 * Copyright (c) Facebook, Inc. and its affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 *
7 *
8 * @format
9 */
10'use strict';
11
12var GraphQLConsoleReporter =
13/*#__PURE__*/
14function () {
15 function GraphQLConsoleReporter(options) {
16 this._verbose = options.verbose;
17 this._quiet = options.quiet;
18 }
19
20 var _proto = GraphQLConsoleReporter.prototype;
21
22 _proto.reportMessage = function reportMessage(message) {
23 if (!this._quiet) {
24 process.stdout.write(message + '\n');
25 }
26 };
27
28 _proto.reportTime = function reportTime(name, ms) {
29 /* $FlowFixMe(>=0.68.0 site=react_native_fb,react_native_oss) This comment
30 * suppresses an error found when Flow v0.68 was deployed. To see the error
31 * delete this comment and run Flow. */
32 if (this._verbose && !this.quiet) {
33 var time = ms === 0 ? require("chalk").gray(' <1ms') : ms < 1000 ? require("chalk").blue(leftPad(5, ms + 'ms')) : require("chalk").red(Math.floor(ms / 10) / 100 + 's');
34 process.stdout.write(' ' + time + ' ' + require("chalk").gray(name) + '\n');
35 }
36 };
37
38 _proto.reportError = function reportError(caughtLocation, error) {
39 if (!this._quiet) {
40 process.stdout.write(require("chalk").red('ERROR:\n' + error.message + '\n'));
41
42 if (this._verbose) {
43 var frames = error.stack.match(/^ {4}at .*$/gm);
44
45 if (frames) {
46 process.stdout.write(require("chalk").gray('From: ' + caughtLocation + '\n' + frames.join('\n') + '\n'));
47 }
48 }
49 }
50 };
51
52 return GraphQLConsoleReporter;
53}();
54
55function leftPad(len, str) {
56 return new Array(len - str.length + 1).join(' ') + str;
57}
58
59module.exports = GraphQLConsoleReporter;
\No newline at end of file