-
Notifications
You must be signed in to change notification settings - Fork 2
/
init.js
39 lines (35 loc) · 1.09 KB
/
init.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
import fs from 'fs'
import Config from '../components/Config.js'
import { pluginRoot } from '../model/path.js'
import Log from '../utils/logs.js'
class Init {
constructor() {
this.initConfig()
}
initConfig() {
const config_default_path = `${pluginRoot}/config/config_default.yaml`
if (!fs.existsSync(config_default_path)) {
Log.e('默认设置文件不存在,请检查或重新安装插件')
return true
}
const config_path = `${pluginRoot}/config/config/config.yaml`
if (!fs.existsSync(config_path)) {
Log.e('设置文件不存在,将使用默认设置文件')
fs.copyFileSync(config_default_path, config_path)
}
const config_default_yaml = Config.getDefConfig()
const config_yaml = Config.getConfig()
for (const key in config_default_yaml) {
if (!(key in config_yaml)) {
config_yaml[key] = config_default_yaml[key]
}
}
for (const key in config_yaml) {
if (!(key in config_default_yaml)) {
delete config_yaml[key]
}
}
Config.setConfig(config_yaml)
}
}
export default new Init()