1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | 'use strict';
|
11 |
|
12 | var GraphQLConsoleReporter =
|
13 |
|
14 | function () {
|
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 | |
30 |
|
31 |
|
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 |
|
55 | function leftPad(len, str) {
|
56 | return new Array(len - str.length + 1).join(' ') + str;
|
57 | }
|
58 |
|
59 | module.exports = GraphQLConsoleReporter; |
\ | No newline at end of file |