forked from Tsuk1ko/cq-picsearcher-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
36 lines (33 loc) · 1.23 KB
/
index.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
require('dotenv').config();
const { existsSync, renameSync } = require('fs-extra');
const { resolve } = require('path');
const {
jsonc: { readSync: readJsoncSync },
} = require('jsonc');
try {
const CONFIG_PATH = resolve(__dirname, './config.jsonc');
const OLD_CONFIG_PATH = resolve(__dirname, './config.json');
const DEFAULT_CONFIG_PATH = resolve(__dirname, './config.default.jsonc');
// 配置迁移
if (existsSync(OLD_CONFIG_PATH) && !existsSync(CONFIG_PATH)) {
renameSync(OLD_CONFIG_PATH, CONFIG_PATH);
}
// 配置检查
readJsoncSync(CONFIG_PATH);
readJsoncSync(DEFAULT_CONFIG_PATH);
} catch (e) {
const { code, message } = e;
const EOL = process.env.npm_execpath ? '\n' : '';
if (code === 'ENOENT') {
console.error(`ERROR: 找不到配置文件 ${e.path}${EOL}`);
} else if (message && message.includes('JSON')) {
console.error(`ERROR: 配置文件 JSON 格式有误\n${message}${EOL}`);
} else console.error(e);
process.exit(1);
}
process.on('SIGHUP', () => process.exit(128 + 1));
process.on('SIGINT', () => process.exit(128 + 2));
process.on('SIGTERM', () => process.exit(128 + 15));
// eslint-disable-next-line no-global-assign
require = require('esm')(module);
module.exports = require('./main');