-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathstatus.js
72 lines (57 loc) · 1.62 KB
/
status.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
var _ = require('lodash');
var async = require('async');
var fs = require('fs');
var http = require('http');
var watch = require('watch');
var sass = require("node-sass");
var path = require('path');
var green = '\u001b[42m \u001b[0m';
var red = '\u001b[41m \u001b[0m';
var exec = require('child_process').exec;
var utils;
module.exports = {
name:'status',
description:'Checks git status across all services',
example:'bosco status',
cmd:cmd
}
function cmd(bosco, args) {
var repos = bosco.config.get('github:repos');
if(!repos) return bosco.error("You are repo-less :( You need to initialise bosco first, try 'bosco fly'.");
bosco.log("Running git status across all repos ...");
var stashRepos = function(cb) {
async.mapSeries(repos, function repoStash(repo, repoCb) {
var repoPath = bosco.getRepoPath(repo);
status(bosco, repoPath, repoCb);
}, function(err) {
cb();
});
}
stashRepos(function() {
bosco.log("Complete");
});
}
function status(bosco, orgPath, next) {
if(!bosco.exists([orgPath,".git"].join("/"))) {
bosco.warn("Doesn't seem to be a git repo: "+ orgPath.blue);
return next();
}
exec('git status', {
cwd: orgPath
}, function(err, stdout, stderr) {
if(err) {
bosco.error(orgPath.blue + " >> " + stderr);
} else {
if(stdout) {
if(stdout.indexOf("Changes not staged") > 0) {
bosco.log(orgPath.blue + ":\n" + stdout);
} else if(stdout.indexOf("Your branch is ahead") > 0) {
bosco.log(orgPath.blue + ":\n" + stdout);
} else {
bosco.log(orgPath.blue + ": " + "OK".green);
}
}
}
next(err);
});
}