UNPKG

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