-
Notifications
You must be signed in to change notification settings - Fork 4
/
config.ts
44 lines (40 loc) · 1.1 KB
/
config.ts
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
import fs from 'fs'
import pack from './package.json'
const configPath = './config.json'
const defaultConfig = {
version: pack.version,
master: {
OneBot: 0,
telegram: 0
},
app: {
OneBot: {
enable: false,
host: '',
port: '',
accessToken: ''
},
telegram: {
enable: false,
token: ''
}
},
logger: {
level: 'INFO'
}
}
if (!fs.existsSync(configPath)) {
fs.writeFileSync(configPath, JSON.stringify(defaultConfig, undefined, 4))
console.log('默认配置创建完成,请修改 config.json 后重新启动程序')
process.exit(0)
} else {
const conf = JSON.parse(fs.readFileSync('./config.json').toString())
if (!conf.version || conf.version !== pack.version) {
const newConf = Object.assign(defaultConfig, conf)
newConf.version = pack.version
fs.writeFileSync(configPath, JSON.stringify(newConf, undefined, 4))
console.log('配置文件版本不匹配,已更新完成,请参考 README.md 手动修改后重新启动程序')
process.exit(0)
}
}
export default JSON.parse(fs.readFileSync('./config.json').toString())