Using promises to resolve which modules has a git remote so the modules wont be skipped on the first check

This commit is contained in:
buxxi 2020-02-17 22:56:06 +01:00
parent be07ff2129
commit 75c8c3f50b
2 changed files with 29 additions and 21 deletions

View File

@ -30,6 +30,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- Fix regression in currentweather module causing 'undefined' to show up when config.hideTemp is false - Fix regression in currentweather module causing 'undefined' to show up when config.hideTemp is false
- Fix FEELS translation for Croatian - Fix FEELS translation for Croatian
- Fixed weather tests [#1840](https://github.com/MichMich/MagicMirror/issues/1840) - Fixed weather tests [#1840](https://github.com/MichMich/MagicMirror/issues/1840)
- Fix update checking skipping 3rd party modules the first time
### Updated ### Updated
- Remove documentation from core repository and link to new dedicated docs site: [docs.magicmirror.builders](https://docs.magicmirror.builders). - Remove documentation from core repository and link to new dedicated docs site: [docs.magicmirror.builders](https://docs.magicmirror.builders).

View File

@ -18,37 +18,30 @@ module.exports = NodeHelper.create({
configureModules: function(modules) { configureModules: function(modules) {
// Push MagicMirror itself , biggest chance it'll show up last in UI and isn't overwritten // Push MagicMirror itself , biggest chance it'll show up last in UI and isn't overwritten
// others will be added in front, asynchronously // others will be added in front
// this method returns promises so we can't wait for every one to resolve before continuing
simpleGits.push({"module": "default", "git": SimpleGit(path.normalize(__dirname + "/../../../"))}); simpleGits.push({"module": "default", "git": SimpleGit(path.normalize(__dirname + "/../../../"))});
var promises = [];
for (moduleName in modules) { for (moduleName in modules) {
if (!this.ignoreUpdateChecking(moduleName)) { if (!this.ignoreUpdateChecking(moduleName)) {
// Default modules are included in the main MagicMirror repo // Default modules are included in the main MagicMirror repo
var moduleFolder = path.normalize(__dirname + "/../../" + moduleName); var moduleFolder = path.normalize(__dirname + "/../../" + moduleName);
var stat;
try { try {
//console.log("checking git for module="+moduleName) //console.log("checking git for module="+moduleName)
stat = fs.statSync(path.join(moduleFolder, ".git")); let stat = fs.statSync(path.join(moduleFolder, ".git"));
promises.push(this.resolveRemote(moduleName, moduleFolder));
} catch(err) { } catch(err) {
// Error when directory .git doesn't exist // Error when directory .git doesn't exist
// This module is not managed with git, skip // This module is not managed with git, skip
continue; continue;
} }
}
}
var res = function(mn, mf) { return Promise.all(promises);
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.unshift({"module": mn, "git": git});
});
}(moduleName, moduleFolder);
}
}
}, },
socketNotificationReceived: function (notification, payload) { socketNotificationReceived: function (notification, payload) {
@ -58,19 +51,33 @@ module.exports = NodeHelper.create({
// if this is the 1st time thru the update check process // if this is the 1st time thru the update check process
if (!this.updateProcessStarted) { if (!this.updateProcessStarted) {
this.updateProcessStarted = true; this.updateProcessStarted = true;
this.configureModules(payload); this.configureModules(payload).then(() => this.performFetch());
this.performFetch();
} }
} }
}, },
performFetch() { resolveRemote: function(moduleName, moduleFolder) {
return new Promise((resolve, reject) => {
var git = SimpleGit(moduleFolder);
git.getRemotes(true, (err, remotes) => {
if (remotes.length < 1 || remotes[0].name.length < 1) {
// No valid remote for folder, skip
return resolve();
}
// Folder has .git and has at least one git remote, watch this folder
simpleGits.unshift({"module": moduleName, "git": git});
resolve();
});
});
},
performFetch: function() {
var self = this; var self = this;
simpleGits.forEach(function(sg) { simpleGits.forEach((sg) => {
sg.git.fetch().status(function(err, data) { sg.git.fetch().status((err, data) => {
data.module = sg.module; data.module = sg.module;
if (!err) { if (!err) {
sg.git.log({"-1": null}, function(err, data2) { sg.git.log({"-1": null}, (err, data2) => {
if (!err && data2.latest && "hash" in data2.latest) { if (!err && data2.latest && "hash" in data2.latest) {
data.hash = data2.latest.hash; data.hash = data2.latest.hash;
self.sendSocketNotification("STATUS", data); self.sendSocketNotification("STATUS", data);