This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
index.js
125 lines (101 loc) · 3.1 KB
/
index.js
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
'use strict';
var gutil = require('gulp-util');
var through = require('through2');
var chalk = require('chalk');
var recess = require('recess');
var RcLoader = require('rcloader');
// prevent RECESS from reading files
recess.Constructor.prototype.read = function () {
setImmediate(function () {
this.data = this.options.contents;
this.parse();
}.bind(this));
};
module.exports = function (options) {
options = options || {};
var rcLoader = new RcLoader('.recessrc', options);
return through.obj(function (file, enc, cb) {
if (file.isNull()) {
cb(null, file);
return;
}
if (file.isStream()) {
cb(new gutil.PluginError('gulp-recess', 'Streaming not supported'));
return;
}
options = rcLoader.for(file.path);
options.contents = file.contents.toString();
recess(file.path, options, function (err, results) {
if (err) {
err.forEach(function (el) {
var realError = new Error(el.message);
// el is an instance of LessError, which does not inherit
// from Error. PluginError expects an instance of Error.
// create a real Error and map LessError properties to it.
realError.columnNumber = el.column;
realError.fileName = el.filename;
realError.lineNumber = el.line;
realError.stack = el.stack;
realError.type = el.name;
var recessError = new gutil.PluginError('gulp-recess', realError, {
showStack: false
});
recessError.recess = {
message: el.message,
filename: el.filename,
line: el.line,
col: el.column
};
this.emit('error', recessError);
}, this);
this.push(file);
return;
}
var data = results[0]; // we only linted one file
var failureCount = 0;
if (data.output.length > 2) {
var match = /([0-9]+) fail/i.exec(chalk.stripColor(data.output[2]));
if (match) {
failureCount = parseInt(match[1]);
}
}
file.recess = {
success: (data.output[1].indexOf('Busted') === -1),
status: chalk.stripColor(data.output[1]).replace(/status: /i,'').trim(),
failureCount: failureCount,
results: data.output.slice(3),
errors: data.errors,
opt: options
};
cb(null, file);
}.bind(this));
});
};
module.exports.reporter = function (options) {
options = options || {};
return through.obj(function (file, enc, cb) {
if (file.isNull()) {
cb(null, file);
return;
}
if (file.isStream()) {
cb(new gutil.PluginError('gulp-recess', 'Streaming not supported'));
return;
}
var recessDataForThisFile = file.recess;
if (recessDataForThisFile && !recessDataForThisFile.success) {
console.log(' [' + chalk.green('gulp-recess') + '] ' + file.relative + ': ' + chalk.red(recessDataForThisFile.status) + ' ' + recessDataForThisFile.failureCount+' failures');
if (!options.minimal) {
console.log(file.recess.results.join('\n'));
}
if (!options.hasOwnProperty('fail') || options.fail) {
cb(new gutil.PluginError('gulp-recess', file.relative + ': ' + file.recess.status + ' ' + recessDataForThisFile.failureCount + ' failures', {
fileName: file.path,
showStack: false
}));
return;
}
}
cb(null, file);
});
};