2016-11-16 18:19:44 +01:00
|
|
|
var SimpleGit = require("simple-git");
|
|
|
|
var simpleGits = [];
|
|
|
|
var fs = require("fs");
|
|
|
|
var path = require("path");
|
2016-11-18 12:53:49 +01:00
|
|
|
var defaultModules = require(__dirname + "/../defaultmodules.js");
|
2016-10-15 13:08:46 +02:00
|
|
|
var NodeHelper = require("node_helper");
|
|
|
|
|
|
|
|
module.exports = NodeHelper.create({
|
|
|
|
|
|
|
|
config: {},
|
|
|
|
|
|
|
|
updateTimer: null,
|
|
|
|
|
|
|
|
start: function () {
|
2016-11-18 12:53:49 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
configureModules: function(modules) {
|
|
|
|
for (moduleName in modules) {
|
|
|
|
if (defaultModules.indexOf(moduleName) < 0) {
|
|
|
|
// Default modules are included in the main MagicMirror repo
|
|
|
|
var moduleFolder = path.normalize(__dirname + "/../../" + moduleName);
|
|
|
|
|
|
|
|
var stat;
|
|
|
|
try {
|
2016-12-01 19:48:53 -03:00
|
|
|
stat = fs.statSync(path.join(moduleFolder, ".git"));
|
2016-11-18 12:53:49 +01:00
|
|
|
} catch(err) {
|
|
|
|
// Error when directory .git doesn't exist
|
|
|
|
// This module is not managed with git, skip
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-12-06 19:57:38 +01:00
|
|
|
var res = function(mn, mf) {
|
|
|
|
var git = SimpleGit(mf);
|
|
|
|
git.getRemotes(true, function(err, remotes) {
|
|
|
|
if (remotes.length < 1 || remotes[0].name.length < 1) {
|
|
|
|
// No valid remote for folder, skip
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Folder has .git and has at least one git remote, watch this folder
|
|
|
|
simpleGits.push({"module": mn, "git": git});
|
|
|
|
});
|
|
|
|
}(moduleName, moduleFolder);
|
2016-11-16 18:19:44 +01:00
|
|
|
}
|
2016-11-18 12:53:49 +01:00
|
|
|
}
|
2016-11-16 18:19:44 +01:00
|
|
|
|
2016-11-18 12:53:49 +01:00
|
|
|
// Push MagicMirror itself last, biggest chance it'll show up last in UI and isn't overwritten
|
|
|
|
simpleGits.push({"module": "default", "git": SimpleGit(path.normalize(__dirname + "/../../../"))});
|
2016-10-15 13:08:46 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
socketNotificationReceived: function (notification, payload) {
|
|
|
|
if (notification === "CONFIG") {
|
|
|
|
this.config = payload;
|
2016-11-18 12:53:49 +01:00
|
|
|
} else if(notification === "MODULES") {
|
|
|
|
this.configureModules(payload);
|
2016-10-15 13:08:46 +02:00
|
|
|
this.preformFetch();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
preformFetch() {
|
|
|
|
var self = this;
|
2016-11-16 18:19:44 +01:00
|
|
|
|
|
|
|
simpleGits.forEach(function(sg) {
|
|
|
|
sg.git.fetch().status(function(err, data) {
|
|
|
|
data.module = sg.module;
|
|
|
|
if (!err) {
|
2017-10-16 09:35:25 +02:00
|
|
|
sg.git.log({"-1": null}, function(err, data2) {
|
2019-01-04 18:12:12 -06:00
|
|
|
if (!err && data2.latest && "hash" in data2.latest) {
|
2019-01-04 09:23:10 -06:00
|
|
|
data.hash = data2.latest.hash;
|
|
|
|
self.sendSocketNotification("STATUS", data);
|
|
|
|
}
|
2017-10-16 09:35:25 +02:00
|
|
|
});
|
2016-11-16 18:19:44 +01:00
|
|
|
}
|
|
|
|
});
|
2016-10-15 13:08:46 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
this.scheduleNextFetch(this.config.updateInterval);
|
|
|
|
},
|
|
|
|
|
|
|
|
scheduleNextFetch: function(delay) {
|
|
|
|
if (delay < 60 * 1000) {
|
|
|
|
delay = 60 * 1000
|
|
|
|
}
|
|
|
|
|
|
|
|
var self = this;
|
|
|
|
clearTimeout(this.updateTimer);
|
|
|
|
this.updateTimer = setTimeout(function() {
|
|
|
|
self.preformFetch();
|
|
|
|
}, delay);
|
|
|
|
}
|
|
|
|
|
2016-10-17 17:03:10 +02:00
|
|
|
});
|