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) { if (err) {
return; 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) { packages.forEach((packageName) => {
packageFile.onServerStart(packageApis(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) { 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;
} }