-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathconfig.js
More file actions
65 lines (65 loc) · 2.65 KB
/
Copy pathconfig.js
File metadata and controls
65 lines (65 loc) · 2.65 KB
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
63
64
65
const fs = require('fs');
const path = require('path')
const pendantsPlugin = {
features: [],
handler: {}
};
function getConfig() {
const myAppPath = path.resolve(__dirname, 'pendants');
const configs = fs.readdirSync(myAppPath)
.map(name => path.resolve(myAppPath, name))
.filter(path => {
const stat = fs.statSync(path)
return stat.isDirectory();
}).map(directory => {
const configFile = path.resolve(directory, 'config.json');
const data = fs.readFileSync(configFile);
const item = JSON.parse(data);
item.src = path.resolve(directory, item.src).replace(__dirname, '.')
// webPreferences
if (item.options && item.options.webPreferences && item.options.webPreferences.preload) {
item.options.webPreferences.preload = path.resolve(directory, item.options.webPreferences.preload)
.replace(__dirname, '.')
}
// setting
if (item.setting) {
item.setting.src = path.resolve(directory, item.setting.src).replace(__dirname, '.');
if (item.setting.options && item.setting.options.webPreferences && item.setting.options.webPreferences.preload) {
item.setting.options.webPreferences.preload = path.resolve(directory, item.setting.options.webPreferences.preload)
.replace(__dirname, '.')
}
}
// plugin
if (item.plugin) {
const { src, features } = item.plugin;
const plugin = require(path.resolve(directory, src).replace(__dirname, '.'));
features.map(({ code: preCode, cmds, explain = item.title }) => {
const code = `pendants.${item.id}.${preCode}`;
pendantsPlugin.features.push({
code,
explain,
cmds
});
pendantsPlugin.handler[code] = plugin[preCode];
})
}
item.title += `|作者:${item.author}`
const tag = `「${item.single ? '单例' : '多例'}」`;
item.description = tag + item.description;
return item;
}).map(item => {item.single === undefined ? true : item.single; return item})
.filter(item => !item.hide)
console.log(configs);
return configs;
}
/**
* id: 唯一字符
* title: 标题
* description: 描述
* author: 作者
*/
const pendantsConfig = [
...getConfig()
]
const getPendantsPlugin = () => pendantsPlugin;
module.exports = { pendantsConfig, getPendantsPlugin };