-
Notifications
You must be signed in to change notification settings - Fork 5
/
npmDomain.js
64 lines (55 loc) · 1.51 KB
/
npmDomain.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
/* eslint-env node */
"use strict";
var DOMAIN_NAME = "hirseNpm";
var childProcess = require("child_process");
var _domainManager;
var child;
function install() {
child = childProcess.exec("npm install", {
cwd: __dirname
});
child.stdout.on("data", function (data) {
_domainManager.emitEvent(DOMAIN_NAME, "out", data);
});
child.stderr.on("data", function (data) {
_domainManager.emitEvent(DOMAIN_NAME, "out", data);
});
child.on("exit", function (code) {
_domainManager.emitEvent(DOMAIN_NAME, "installComplete", code);
});
}
function init(domainManager) {
_domainManager = domainManager;
if (!domainManager.hasDomain(DOMAIN_NAME)) {
domainManager.registerDomain(DOMAIN_NAME, {
major: 0,
minor: 1
});
}
domainManager.registerCommand(
DOMAIN_NAME, // domain name
"install", // command name
install, // command handler function
false, // this command is synchronous in Node
"Calls npm install"
);
domainManager.registerEvent(
DOMAIN_NAME, // domain name
"out", // event name
[{
name: "mesage",
type: "string",
description: "Message body"
}]
);
domainManager.registerEvent(
DOMAIN_NAME, // domain name
"installComplete", // event name
[{
name: "code",
type: "number",
description: "Exit Code"
}]
);
}
exports.init = init;