-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathconfig.js
62 lines (56 loc) · 2.45 KB
/
config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
const path = require("path");
//todo: reduce code duplication
module.exports = {
getPluginPackage(configPath, pluginConfig){
return require(path.resolve(configPath, "..", pluginConfig.path, "package.json"));
},
async buildClientPluginMap(configPath){
let config = await require(configPath)
if(typeof config === "function"){
config = await config();
}
let pluginConfigs = config.plugins;
let clientConfigs = pluginConfigs.reduce((acc, plugin) => {
let pluginPackage = this.getPluginPackage(configPath, plugin)
if (pluginPackage.pluginbot.client) {
let pluginClientPath = path.resolve(configPath, "..", plugin.path, pluginPackage.pluginbot.client.main);
acc[pluginPackage.name] = pluginClientPath
}
return acc;
}, {});
return clientConfigs;
},
async buildClientConfig(configPath){
let config = await require(configPath);
if(typeof config === "function"){
config = await config();
}
let pluginConfigs = config.plugins;
let clientConfigs = pluginConfigs.reduce((acc, plugin) => {
let pluginPackage = this.getPluginPackage(configPath, plugin)
if (pluginPackage.pluginbot.client) {
let pluginClientPath = path.resolve(configPath, "..", plugin.path, pluginPackage.pluginbot.client.main);
acc[pluginPackage.name] = {pluginPackage,clientConfig: plugin.client, path: plugin.path}
}
return acc;
}, {});
return {plugins : clientConfigs, config : config};
},
async buildServerConfig(configPath){
let config = await require(configPath);
if (typeof config === "function") {
config = await config();
}
let pluginConfigs = config.plugins;
let serverConfigs = pluginConfigs.reduce((acc, plugin) => {
let pluginPackage = this.getPluginPackage(configPath, plugin)
let pluginbot =pluginPackage.pluginbot;
if (pluginbot && (pluginbot.server || pluginbot.main)) {
let pluginServerPath = path.resolve(configPath, "..", plugin.path, (pluginbot.main || pluginbot.server.main));
acc[pluginPackage.name] = {pluginPackage, config : plugin, path: plugin.path}
}
return acc;
}, {});
return {plugins : serverConfigs, config : config};
}
}