1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | var grunt = require('../grunt');
|
11 |
|
12 |
|
13 | var fail = module.exports = {};
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 | function writeln(e, mode) {
|
26 | grunt.log.muted = false;
|
27 |
|
28 | var tags = {
|
29 | warn: ['<'.red + 'WARN'.yellow + '>'.red, '</'.red + 'WARN'.yellow + '>'.red],
|
30 | fatal: ['<'.red + 'FATAL'.yellow + '>'.red, '</'.red + 'FATAL'.yellow + '>'.red]
|
31 | };
|
32 | var msg = String(e.message || e) + '\x07';
|
33 | if (mode === 'warn') {
|
34 | msg += ' ' + (grunt.option('force') ? 'Used --force, continuing.'.underline : 'Use --force to continue.');
|
35 | }
|
36 | grunt.log.writeln([tags[mode][0], msg.yellow, tags[mode][1]].join(' '));
|
37 | }
|
38 |
|
39 |
|
40 | fail.fatal = function(e, errcode) {
|
41 | writeln(e, 'fatal');
|
42 | process.reallyExit(typeof errcode === 'number' ? errcode : 1);
|
43 | };
|
44 |
|
45 |
|
46 | fail.errorcount = 0;
|
47 | fail.warncount = 0;
|
48 |
|
49 |
|
50 |
|
51 | fail.warnAlternate = null;
|
52 |
|
53 |
|
54 | fail.warn = function(e, errcode) {
|
55 | var message = typeof e === 'string' ? e : e.message;
|
56 | fail.warncount++;
|
57 | writeln(message, 'warn');
|
58 |
|
59 | if (!grunt.option('force')) {
|
60 | if (fail.warnAlternate) {
|
61 | fail.warnAlternate();
|
62 | } else {
|
63 |
|
64 | if (grunt.option('debug') >= 9) {
|
65 | if (e.origError && e.origError.stack) {
|
66 | console.log(e.origError.stack);
|
67 | } else if (e.stack) {
|
68 | console.log(e.stack);
|
69 | }
|
70 | }
|
71 |
|
72 | grunt.log.writeln().fail('Aborted due to warnings.');
|
73 | process.reallyExit(typeof errcode === 'number' ? errcode : 2);
|
74 | }
|
75 | }
|
76 | };
|
77 |
|
78 |
|
79 | fail.report = function() {
|
80 | if (fail.warncount > 0) {
|
81 | grunt.log.writeln().fail('Done, but with warnings.');
|
82 | } else {
|
83 | grunt.log.writeln().success('Done, without errors.');
|
84 | }
|
85 | };
|