2018-01-05 17:40:34 +00:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const fs = require("fs");
|
|
|
|
const colors = require("colors/safe");
|
|
|
|
const Helper = require("../../helper");
|
|
|
|
const themes = require("./themes");
|
|
|
|
const packageMap = new Map();
|
|
|
|
|
|
|
|
const stylesheets = [];
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
getStylesheets,
|
|
|
|
getPackage,
|
|
|
|
loadPackages,
|
|
|
|
};
|
|
|
|
|
|
|
|
const packageApis = function(packageName) {
|
|
|
|
return {
|
|
|
|
Stylesheets: {
|
|
|
|
addFile: addStylesheet.bind(this, packageName),
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
function addStylesheet(packageName, filename) {
|
|
|
|
stylesheets.push(packageName + "/" + filename);
|
|
|
|
}
|
|
|
|
|
|
|
|
function getStylesheets() {
|
|
|
|
return stylesheets;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getPackage(name) {
|
|
|
|
return packageMap.get(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
function loadPackages() {
|
|
|
|
fs.readdir(Helper.getPackagesPath(), (err, packages) => {
|
|
|
|
if (err) {
|
|
|
|
return;
|
|
|
|
}
|
2018-02-05 06:30:57 +00:00
|
|
|
|
2018-01-05 17:40:34 +00:00
|
|
|
packages.forEach((packageName) => {
|
2018-02-05 06:30:57 +00:00
|
|
|
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));
|
|
|
|
}
|
|
|
|
});
|
2018-01-05 17:40:34 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function getModuleInfo(packageName) {
|
2018-02-05 06:30:57 +00:00
|
|
|
const module = require(Helper.getPackageModulePath(packageName));
|
|
|
|
|
2018-01-05 17:40:34 +00:00
|
|
|
if (!module.thelounge) {
|
|
|
|
log.warn(`Specified package ${colors.yellow(packageName)} doesn't have required information.`);
|
|
|
|
return;
|
|
|
|
}
|
2018-02-05 06:30:57 +00:00
|
|
|
|
2018-01-05 17:40:34 +00:00
|
|
|
return module.thelounge;
|
|
|
|
}
|