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