forked from richmarr/stagecoach
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ps.js
executable file
·65 lines (52 loc) · 1.6 KB
/
ps.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
#!/usr/bin/env node
var EventEmitter = require('events').EventEmitter;
var propagit = require('propagit');
var archy = require('archy');
var argv = require('../lib/argv');
if (!argv.hub) return console.error('Specify a --hub or set a remote.');
var p = propagit(argv);
p.on('error', function (err) {
console.dir(err);
});
p.hub.on('up', argv.json ? raw : text);
function text (hub) {
var em = new EventEmitter;
em.on('data', function (key, procs) {
var s = archy({
label : 'drone#' + key,
nodes : Object.keys(procs).map(function (id) {
var p = procs[id];
return {
label : 'pid#' + id,
nodes : [
'status: ' + p.status,
'commit: ' + p.repo + '/' + p.commit,
'command: ' + p.command.join(' '),
],
}
}),
});
console.log(Object.keys(procs).length ? s : s.replace(/\n$/, ''));
});
em.on('end', function () {
p.hub.close();
});
hub.ps(em.emit.bind(em));
}
function raw (hub) {
var em = new EventEmitter;
console.log('{');
var ix = 0;
em.on('data', function (key, procs) {
if (ix++ > 0) process.stdout.write(',\n');
process.stdout.write(
' ' + JSON.stringify(key) + ' : '
+ JSON.stringify(procs).replace(/\n/g, '\n ')
);
});
em.on('end', function () {
console.log('\n}');
p.hub.close();
});
hub.ps(em.emit.bind(em));
}