forked from c9/cloud9
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugin.js
More file actions
70 lines (58 loc) · 1.85 KB
/
plugin.js
File metadata and controls
70 lines (58 loc) · 1.85 KB
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
/**
* @copyright 2010, Ajax.org Services B.V.
* @license GPLv3 <http://www.gnu.org/licenses/gpl.txt>
*/
var Spawn = require("child_process").spawn;
var sys = require("sys");
function cloud9Plugin() {}
sys.inherits(cloud9Plugin, process.EventEmitter);
(function() {
this.getHooks = function() {
return this.hooks || [];
};
this.extend = function(dest, src) {
for (var prop in src) {
dest[prop] = src[prop];
}
return dest;
};
this.sendResult = function(sid, type, msg) {
//console.log("sending result to client: ", type, JSON.stringify(msg));
this.ide.broadcast(JSON.stringify({
type : "result",
subtype: type || "error",
sid : sid || 0,
body : msg || "Access denied."
}), this.name);
};
this.spawnCommand = function(cmd, args, cwd, onerror, ondata, onexit) {
var child = this.activePs = Spawn(cmd, args || [], {cwd: cwd || this.server.workspaceDir}),
out = "",
err = "",
_self = this;
child.stdout.on("data", sender("stdout"));
child.stderr.on("data", sender("stderr"));
function sender(stream) {
return function(data) {
var s = data.toString("utf8");
if (stream == "stderr") {
err += s;
onerror && onerror(s);
}
else {
out += s;
ondata && ondata(s);
}
};
}
child.on("exit", function(code) {
delete _self.activePs;
onexit && onexit(code, err, out);
});
return child;
};
this.dispose = function(callback) {
callback();
};
}).call(cloud9Plugin.prototype);
module.exports = cloud9Plugin;