1 | "use strict";
|
2 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
3 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
4 | };
|
5 | Object.defineProperty(exports, "__esModule", { value: true });
|
6 | exports.formatResult = exports.format = void 0;
|
7 | const chalk_1 = __importDefault(require("chalk"));
|
8 | const DEFAULT_SIGNS = [' ', '⚠', '✖'];
|
9 | const DEFAULT_COLORS = ['white', 'yellow', 'red'];
|
10 | function format(report = {}, options = {}) {
|
11 | const { results = [] } = report;
|
12 | const fi = (result) => formatInput(result, options);
|
13 | const fr = (result) => formatResult(result, options);
|
14 | return results
|
15 | .filter((r) => Array.isArray(r.warnings) || Array.isArray(r.errors))
|
16 | .map((result) => [...fi(result), ...fr(result)])
|
17 | .reduce((acc, item) => (Array.isArray(item) ? [...acc, ...item] : [...acc, item]), [])
|
18 | .join('\n');
|
19 | }
|
20 | exports.format = format;
|
21 | function formatInput(result, options = {}) {
|
22 | const { color: enabled = true } = options;
|
23 | const { errors = [], warnings = [], input = '' } = result;
|
24 | if (!input) {
|
25 | return [''];
|
26 | }
|
27 | const sign = '⧗';
|
28 | const decoration = enabled ? chalk_1.default.gray(sign) : sign;
|
29 | const commitText = errors.length > 0 ? input : input.split('\n')[0];
|
30 | const decoratedInput = enabled ? chalk_1.default.bold(commitText) : commitText;
|
31 | const hasProblems = errors.length > 0 || warnings.length > 0;
|
32 | return options.verbose || hasProblems
|
33 | ? [`${decoration} input: ${decoratedInput}`]
|
34 | : [];
|
35 | }
|
36 | function formatResult(result = {}, options = {}) {
|
37 | const { signs = DEFAULT_SIGNS, colors = DEFAULT_COLORS, color: enabled = true, } = options;
|
38 | const { errors = [], warnings = [] } = result;
|
39 | const problems = [...errors, ...warnings].map((problem) => {
|
40 | const sign = signs[problem.level] || '';
|
41 | const color = colors[problem.level] || 'white';
|
42 | const decoration = enabled ? chalk_1.default[color](sign) : sign;
|
43 | const name = enabled
|
44 | ? chalk_1.default.grey(`[${problem.name}]`)
|
45 | : `[${problem.name}]`;
|
46 | return `${decoration} ${problem.message} ${name}`;
|
47 | });
|
48 | const sign = selectSign(result);
|
49 | const color = selectColor(result);
|
50 | const deco = enabled ? chalk_1.default[color](sign) : sign;
|
51 | const el = errors.length;
|
52 | const wl = warnings.length;
|
53 | const hasProblems = problems.length > 0;
|
54 | const summary = options.verbose || hasProblems
|
55 | ? `${deco} found ${el} problems, ${wl} warnings`
|
56 | : undefined;
|
57 | const fmtSummary = enabled && typeof summary === 'string' ? chalk_1.default.bold(summary) : summary;
|
58 | const help = hasProblems ? `ⓘ Get help: ${options.helpUrl}` : undefined;
|
59 | return [
|
60 | ...problems,
|
61 | hasProblems ? '' : undefined,
|
62 | fmtSummary,
|
63 | help,
|
64 | help ? '' : undefined,
|
65 | ].filter((line) => typeof line === 'string');
|
66 | }
|
67 | exports.formatResult = formatResult;
|
68 | exports.default = format;
|
69 | function selectSign(result) {
|
70 | if ((result.errors || []).length > 0) {
|
71 | return '✖';
|
72 | }
|
73 | return (result.warnings || []).length ? '⚠' : '✔';
|
74 | }
|
75 | function selectColor(result) {
|
76 | if ((result.errors || []).length > 0) {
|
77 | return 'red';
|
78 | }
|
79 | return (result.warnings || []).length ? 'yellow' : 'green';
|
80 | }
|
81 |
|
\ | No newline at end of file |