1 | import { tsModule } from "./tsproxy";
|
2 | import { red, white, yellow } from "colors/safe";
|
3 | import { IContext } from "./context";
|
4 | import { IDiagnostics } from "./tscache";
|
5 | import * as _ from "lodash";
|
6 |
|
7 | export function printDiagnostics(context: IContext, diagnostics: IDiagnostics[], pretty: boolean): void
|
8 | {
|
9 | _.each(diagnostics, (diagnostic) =>
|
10 | {
|
11 | let print;
|
12 | let color;
|
13 | let category;
|
14 | switch (diagnostic.category)
|
15 | {
|
16 | case tsModule.DiagnosticCategory.Message:
|
17 | print = context.info;
|
18 | color = white;
|
19 | category = "";
|
20 | break;
|
21 | case tsModule.DiagnosticCategory.Error:
|
22 | print = context.error;
|
23 | color = red;
|
24 | category = "error";
|
25 | break;
|
26 | case tsModule.DiagnosticCategory.Warning:
|
27 | default:
|
28 | print = context.warn;
|
29 | color = yellow;
|
30 | category = "warning";
|
31 | break;
|
32 | }
|
33 |
|
34 | const type = diagnostic.type + " ";
|
35 |
|
36 | if (pretty)
|
37 | print.call(context, [`${diagnostic.formatted}`]);
|
38 | else
|
39 | {
|
40 | if (diagnostic.fileLine !== undefined)
|
41 | print.call(context, [`${diagnostic.fileLine}: ${type}${category} TS${diagnostic.code} ${color(diagnostic.flatMessage)}`]);
|
42 | else
|
43 | print.call(context, [`${type}${category} TS${diagnostic.code} ${color(diagnostic.flatMessage)}`]);
|
44 | }
|
45 | });
|
46 | }
|