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