aboutsummaryrefslogtreecommitdiff
path: root/bin/coveralls.js
blob: 38e8071aff0a8f82e46fff060331c472e0b74481 (plain)
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
#!/usr/bin/env node
var fs = require('fs');
var path = require('path');
var YAML = require('libyaml');
var sendToCoveralls = require('../lib/sendToCoveralls');
var convertLcovToCoveralls = require('../lib/convertLcovToCoveralls');
var repo_token;

process.stdin.resume();
process.stdin.setEncoding('utf8');

var input = '';

process.stdin.on('data', function(chunk) {
    input += chunk;
});

process.stdin.on('end', function() {
    inputToCoveralls(input);
});

var inputToCoveralls = function(input){
    console.log(input);
    var libDir = process.argv[2] || '';
    
    if (process.env.COVERALLS_REPO_TOKEN) {
      repo_token = process.env.COVERALLS_REPO_TOKEN;
    } else {
      var yml = path.join(process.cwd(), '.coveralls.yml');
      try {
        if (fs.statSync(yml).isFile()) {
          repo_token = YAML.readFileSync(yml)[0].repo_token;
        }
      } catch(ex){
        console.log("Repo token could not be determined.  Continuing without it.");
      }
    }
    
    convertLcovToCoveralls(input, libDir, repo_token, function(err, postData){
    if (err){
      throw err;
    }
    sendToCoveralls(postData, function(err, response, body){
      if (err){
        throw err;
      }
      if (response.statusCode >= 400){
        throw "Bad response: " + response.statusCode + " " + body;
      }
      console.log(response.statusCode);
      console.log(body);
    });
  });

};