1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60 |
1
1
1
1
7
7
8
8
3
1 | 'use strict';
/**
* @typedef {{color: boolean, cwd: string, report: function(string), warn: function(string), getMessages: function():Array.<MESSAGE>}} CONTEXT
*/
/**
* @typedef {{msg: string, level: MESSAGE_LEVEL, file: string}} MESSAGE
*/
/**
* Enum for tri-state values.
* @enum {string}
*/
var MESSAGE_LEVEL = {
ERROR: 'ERROR',
WARN: 'WARN',
INFO: 'INFO'
};
var _ = require('lodash');
/**
* @type {CONTEXT}
*/
var context = {
messages: [],
color: true,
cwd: process.cwd(),
report: function (msg) {
console.log(msg);
},
info: function (msg, file, line, column) {
context.issue(MESSAGE_LEVEL.INFO, msg, file, line, column);
},
warn: function (msg, file, line, column) {
context.issue(MESSAGE_LEVEL.WARN, msg, file, line, column);
},
error: function (msg, file, line, column, index) {
context.issue(MESSAGE_LEVEL.ERROR, msg, file, line, column, index);
},
issue: function (level, msg, file, line, column, index) {
context.messages.push({level: level, msg: msg, file: file || null, line: line || -1, column: column || -1, index: index || -1});
},
getMessages: function () {
return context.messages;
},
clear: function () {
context.messages = [];
},
hasErrors: function () {
return _.some(context.messages, {level: MESSAGE_LEVEL.ERROR});
},
options: {
verbose: false,
outFile: null,
format: 'stylish'
},
MESSAGE_LEVEL: MESSAGE_LEVEL
};
module.exports = context; |