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,34 +39,40 @@ function loadPackages() {
if (err) {
return;
}
packages.forEach((packageName) => {
const packageFile = getModuleInfo(packageName);
if (!packageFile) {
return;
}
packageMap.set(packageName, packageFile);
if (packageFile.type === "theme") {
themes.addTheme(packageName, packageFile);
}
if (packageFile.onServerStart) {
packageFile.onServerStart(packageApis(packageName));
}
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);
}
if (packageFile.onServerStart) {
packageFile.onServerStart(packageApis(packageName));
}
});
});
});
}
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;
}