1 | var through = require('through2'),
|
2 | gutil = require('gulp-util'),
|
3 | coveralls = require('coveralls');
|
4 |
|
5 | module.exports = function() {
|
6 | return through.obj(function(file, enc, callback) {
|
7 | var stream = this;
|
8 |
|
9 | function handleError(done, err) {
|
10 | if (err){
|
11 | stream.emit('error', new gutil.PluginError('gulp-coveralls', err));
|
12 | done();
|
13 | }
|
14 | }
|
15 |
|
16 | function sendToCoverallsCallback(done, err, response, body) {
|
17 | handleError(done, err);
|
18 | if (response.statusCode >= 400){
|
19 | handleError(done, 'Bad response:' + response.statusCode + ' ' + body);
|
20 | } else {
|
21 | done();
|
22 | }
|
23 | }
|
24 |
|
25 | function sendToCoveralls(input, done) {
|
26 | coveralls.getBaseOptions(function(err, options){
|
27 | options.filepath = '.';
|
28 | coveralls.convertLcovToCoveralls(input, options, function(err, postData){
|
29 | handleError(done, err);
|
30 | coveralls.sendToCoveralls(postData, function(err, response, body){
|
31 | sendToCoverallsCallback(done, err, response, body);
|
32 | });
|
33 | });
|
34 | });
|
35 | }
|
36 |
|
37 | if (file.isNull()) {
|
38 | this.push(file);
|
39 | return callback();
|
40 | }
|
41 |
|
42 | if (file.isStream()) {
|
43 | this.emit('error', new gutil.PluginError('gulp-coveralls', 'Stream content is not supported'));
|
44 | return callback();
|
45 | }
|
46 |
|
47 | if (file.isBuffer()) {
|
48 | sendToCoveralls(file.contents.toString(), callback);
|
49 | this.push(file);
|
50 | }
|
51 | });
|
52 | };
|