1 |
|
2 | import * as _ from "lodash";
|
3 |
|
4 | export interface IRollupContext
|
5 | {
|
6 | warn(message: string): void;
|
7 | error(message: string): void;
|
8 | }
|
9 |
|
10 | export interface IContext
|
11 | {
|
12 | warn(message: string | (() => string)): void;
|
13 | error(message: string | (() => string)): void;
|
14 | info(message: string | (() => string)): void;
|
15 | debug(message: string | (() => string)): void;
|
16 | }
|
17 |
|
18 | export enum VerbosityLevel
|
19 | {
|
20 | Error = 0,
|
21 | Warning,
|
22 | Info,
|
23 | Debug,
|
24 | }
|
25 |
|
26 | export class ConsoleContext implements IContext
|
27 | {
|
28 | constructor(private verbosity: VerbosityLevel, private prefix: string = "")
|
29 | {
|
30 | }
|
31 |
|
32 | public warn(message: string | (() => string)): void
|
33 | {
|
34 | if (this.verbosity < VerbosityLevel.Warning)
|
35 | return;
|
36 | console.log(`${this.prefix}${_.isFunction(message) ? message() : message}`);
|
37 | }
|
38 |
|
39 | public error(message: string | (() => string)): void
|
40 | {
|
41 | if (this.verbosity < VerbosityLevel.Error)
|
42 | return;
|
43 | console.log(`${this.prefix}${_.isFunction(message) ? message() : message}`);
|
44 | }
|
45 |
|
46 | public info(message: string | (() => string)): void
|
47 | {
|
48 | if (this.verbosity < VerbosityLevel.Info)
|
49 | return;
|
50 | console.log(`${this.prefix}${_.isFunction(message) ? message() : message}`);
|
51 | }
|
52 |
|
53 | public debug(message: string | (() => string)): void
|
54 | {
|
55 | if (this.verbosity < VerbosityLevel.Debug)
|
56 | return;
|
57 | console.log(`${this.prefix}${_.isFunction(message) ? message() : message}`);
|
58 | }
|
59 | }
|
60 |
|
\ | No newline at end of file |