Ensure packages loaded are directories

This commit is contained in:
Jérémie Astori 2018-02-05 01:30:57 -05:00
parent 0b3741859f
commit b5d96d215f
No known key found for this signature in database
GPG Key ID: B9A4F245CD67BDE8

View File

@ -39,12 +39,21 @@ function loadPackages() {
if (err) {
return;
}
packages.forEach((packageName) => {
fs.stat(Helper.getPackageModulePath(packageName), function(err2, stat) {
if (err2 || !stat.isDirectory()) {
return;
}
const packageFile = getModuleInfo(packageName);
if (!packageFile) {
return;
}
packageMap.set(packageName, packageFile);
if (packageFile.type === "theme") {
themes.addTheme(packageName, packageFile);
}
@ -54,19 +63,16 @@ function loadPackages() {
}
});
});
});
}
function getModuleInfo(packageName) {
let module;
try {
module = require(Helper.getPackageModulePath(packageName));
} catch (e) {
log.warn(`Specified package ${colors.yellow(packageName)} is not installed in packages directory`);
return;
}
const module = require(Helper.getPackageModulePath(packageName));
if (!module.thelounge) {
log.warn(`Specified package ${colors.yellow(packageName)} doesn't have required information.`);
return;
}
return module.thelounge;
}