1 | 'use strict';
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | const MESSAGE_LEVEL = {
|
14 | ERROR: 'ERROR',
|
15 | WARN: 'WARN',
|
16 | INFO: 'INFO'
|
17 | };
|
18 |
|
19 | const _ = require('lodash');
|
20 | const err = require('./RTCodeError');
|
21 | const norm = err.RTCodeError.norm;
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 | const context = {
|
28 |
|
29 | messages: [],
|
30 |
|
31 | color: true,
|
32 |
|
33 | cwd: process.cwd(),
|
34 | report(msg) {
|
35 | console.log(msg);
|
36 | },
|
37 | verbose(msg) {
|
38 | if (context.options.verbose) {
|
39 | console.log(msg);
|
40 | }
|
41 | },
|
42 | info(msg, file, line, column) {
|
43 | context.issue(MESSAGE_LEVEL.INFO, msg, file, line, column);
|
44 | },
|
45 | warn(msg, file, line, column, startOffset, endOffset) {
|
46 | context.issue(MESSAGE_LEVEL.WARN, msg, file, line, column, startOffset, endOffset);
|
47 | },
|
48 | error(msg, file, line, column, startOffset, endOffset) {
|
49 | context.issue(MESSAGE_LEVEL.ERROR, msg, file, line, column, startOffset, endOffset);
|
50 | },
|
51 | |
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 | issue(level, msg, file, line, column, startOffset, endOffset) {
|
61 | context.messages.push({level, msg, file: file || null, line: norm(line), column: norm(column), index: norm(startOffset), startOffset: norm(startOffset), endOffset: norm(endOffset)});
|
62 | },
|
63 | getMessages() {
|
64 | return context.messages;
|
65 | },
|
66 | clear() {
|
67 | context.messages = [];
|
68 | },
|
69 | hasErrors() {
|
70 | return _.some(context.messages, {level: MESSAGE_LEVEL.ERROR});
|
71 | },
|
72 | options: {
|
73 | verbose: false,
|
74 | outFile: null,
|
75 | format: 'stylish'
|
76 | },
|
77 | MESSAGE_LEVEL
|
78 | };
|
79 |
|
80 | module.exports = context;
|