-
Notifications
You must be signed in to change notification settings - Fork 2
/
Config.js
45 lines (41 loc) · 1002 Bytes
/
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
import YAML from 'yaml'
import fs from 'fs'
import { pluginRoot } from '../model/path.js'
import Log from '../utils/logs.js'
class Config {
getConfig() {
try {
const config_data = YAML.parse(
fs.readFileSync(`${pluginRoot}/config/config/config.yaml`, 'utf-8')
)
return config_data
} catch (err) {
Log.e('读取config.yaml失败', err)
return false
}
}
getDefConfig() {
try {
const config_default_data = YAML.parse(
fs.readFileSync(`${pluginRoot}/config/config_default.yaml`, 'utf-8')
)
return config_default_data
} catch (err) {
Log.e('读取config_default.yaml失败', err)
return false
}
}
setConfig(config_data) {
try {
fs.writeFileSync(
`${pluginRoot}/config/config/config.yaml`,
YAML.stringify(config_data),
)
return true
} catch (err) {
Log.e('写入config.yaml失败', err)
return false
}
}
}
export default new Config()