UNPKG

2.43 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3var chalk_1 = require("chalk");
4var logUpdate = require("log-update");
5var indentString = require("indent-string");
6var logSymbol = require("log-symbols");
7var UpdateRenderer = require("listr-update-renderer");
8var common_tags_1 = require("common-tags");
9var errors_1 = require("../errors");
10var graphql_codegen_core_1 = require("graphql-codegen-core");
11var Renderer = /** @class */ (function () {
12 function Renderer(tasks, options) {
13 this.updateRenderer = new UpdateRenderer(tasks, options);
14 }
15 Renderer.prototype.render = function () {
16 return this.updateRenderer.render();
17 };
18 Renderer.prototype.end = function (err) {
19 this.updateRenderer.end(err);
20 if (typeof err === undefined) {
21 logUpdate.clear();
22 return;
23 }
24 // persist the output
25 logUpdate.done();
26 // show errors
27 if (err) {
28 var errorCount = err.errors ? err.errors.length : 0;
29 if (errorCount > 0) {
30 var count = indentString(chalk_1.default.red.bold("Found " + errorCount + " error" + (errorCount > 1 ? 's' : '')), 1);
31 var details = err.errors
32 .map(function (error) {
33 graphql_codegen_core_1.debugLog("[CLI] Exited with an error", error);
34 return errors_1.isDetailedError(error) ? error.details : error;
35 })
36 .map(function (msg, i) {
37 var source = err.errors[i].source;
38 msg = chalk_1.default.gray(indentString(common_tags_1.stripIndent("" + msg), 4));
39 if (source) {
40 var sourceOfError = typeof source === 'string' ? source : source.name;
41 var title = indentString(logSymbol.error + " " + sourceOfError, 2);
42 return [title, msg].join('\n');
43 }
44 return msg;
45 })
46 .join('\n\n');
47 logUpdate(['', count, details, ''].join('\n\n'));
48 }
49 else {
50 logUpdate(chalk_1.default.red.bold(err.message));
51 }
52 }
53 logUpdate.done();
54 graphql_codegen_core_1.printLogs();
55 };
56 return Renderer;
57}());
58exports.Renderer = Renderer;
59//# sourceMappingURL=listr-renderer.js.map
\No newline at end of file