This repository was archived by the owner on Aug 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnode_helper.js
70 lines (62 loc) · 2.37 KB
/
node_helper.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
const git = require('simple-git/promise');
const path = require("path");
const promiseReflect = require("promise-reflect");
const { exec } = require('child_process');
var repositories = {};
module.exports = NodeHelper.create({
socketNotificationReceived: function (notification, payload) {
var self = this;
if (notification === "PULL") {
this.pullModule(payload);
} else if (notification === "PULL_ALL_MODULES") {
this.pullAllModules(payload);
} else if (notification === "PULL_MIRROR") {
this.pullMirror();
} else if (notification === "PULL_EVERYTHING") {
this.pullEverything(payload);
} else if (notification === "TEST"){
self.sendSocketNotification("TEST", "test");
}else if(notification === "EXECUTE_SCRIPT"){
exec(payload, (err, stdout, stderr) => {
if(err){
self.sendSocketNotification("EXECUTION_ERROR", stderr);
}else{
self.sendSocketNotification("EXECUTION_SUCCESS", stdout);
}
});
return;
}
if (Object.keys(repositories).length > 0) {
var result = {};
var pullPromises = Object.values(repositories).map(this.pullRepository);
Promise.all(pullPromises.map(promiseReflect)).then(pullResults => {
console.log(pullResults);
pullResults.forEach(function (item, index) {
result[Object.keys(repositories)[index]] = item;
});
self.sendSocketNotification('PULL_RESULT', result);
});
}
},
pullModule: function (moduleName) {
repositories[moduleName] = path.normalize(__dirname + "/../../modules/" + moduleName);
},
pullAllModules: function (modules) {
var self = this;
modules.forEach(function (module) {
self.pullModule(module);
});
},
pullMirror: function () {
repositories["mirror"] = path.normalize(__dirname + "/../../");
},
pullEverything: function (modules) {
this.pullAllModules(modules);
this.pullMirror();
},
pullRepository: async function (localPath) {
console.log("pulling repository at " + localPath);
var repository = git(localPath);
return await repository.pull();
}
});