-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdomain.js
108 lines (96 loc) · 2.69 KB
/
domain.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/* eslint-env node */
"use strict";
var DOMAIN_NAME = "hirseUngit";
var isWin = /^win/.test(process.platform);
var childProcess = require("child_process");
var _domainManager;
var child;
function start() {
var args = ["--no-b", "--maxNAutoRestartOnCrash=0", "--ungitVersionCheckOverride"];
child = childProcess.fork("node_modules/ungit/bin/ungit", args, {
cwd: __dirname,
silent: true
});
child.stdout.on("data", function (buffer) {
_domainManager.emitEvent(DOMAIN_NAME, "out", buffer.toString());
});
child.stderr.on("data", function (buffer) {
_domainManager.emitEvent(DOMAIN_NAME, "stderr", buffer.toString());
});
child.on("error", function (code) {
_domainManager.emitEvent(DOMAIN_NAME, "error", code);
});
child.on("close", function (code) {
child = null;
_domainManager.emitEvent(DOMAIN_NAME, "close", code);
});
}
function kill() {
if (child) {
if (isWin) {
childProcess.spawn("taskkill", ["/pid", child.pid, "/t", "/f"]);
} else {
child.kill();
}
}
}
function init(domainManager) {
_domainManager = domainManager;
if (!domainManager.hasDomain(DOMAIN_NAME)) {
domainManager.registerDomain(DOMAIN_NAME, {
major: 0,
minor: 1
});
}
domainManager.registerCommand(
DOMAIN_NAME, // domain name
"start", // command name
start, // command handler function
false, // this command is synchronous in Node
"Starts the ungit process"
);
domainManager.registerCommand(
DOMAIN_NAME, // domain name
"kill", // command name
kill, // command handler function
false, // this command is synchronous in Node
"Kills the ungit process"
);
domainManager.registerEvent(
DOMAIN_NAME, // domain name
"out", // event name
[{
name: "mesage",
type: "string",
description: "Message body"
}]
);
domainManager.registerEvent(
DOMAIN_NAME, // domain name
"stderr", // event name
[{
name: "mesage",
type: "string",
description: "message body"
}]
);
domainManager.registerEvent(
DOMAIN_NAME, // domain name
"error", // event name
[{
name: "code",
type: "string",
description: "Exit code"
}]
);
domainManager.registerEvent(
DOMAIN_NAME, // domain name
"close", // event name
[{
name: "code",
type: "string",
description: "Exit code"
}]
);
}
exports.init = init;