|
import setLog from './log.js' |
|
import cfg from "./config.js" |
|
import redisInit from './redis.js' |
|
import { checkRun } from './check.js' |
|
import fs from 'node:fs' |
|
|
|
|
|
process.title = cfg.package.name |
|
|
|
process.env.TZ = 'Asia/Shanghai' |
|
|
|
|
|
process.on('uncaughtException', (error) => { |
|
let err = error |
|
if (logger) { |
|
logger.error(err) |
|
} else { |
|
console.log(err) |
|
} |
|
}) |
|
|
|
|
|
process.on('unhandledRejection', (error, promise) => { |
|
let err = error |
|
if (logger) { |
|
logger.error(err) |
|
} else { |
|
console.log(err) |
|
} |
|
}) |
|
|
|
|
|
process.on('exit', async (code) => { |
|
if (typeof redis != 'undefined' && typeof test == 'undefined') { |
|
await redis.save() |
|
} |
|
}) |
|
|
|
await checkInit() |
|
|
|
|
|
async function checkInit () { |
|
|
|
if (!fs.existsSync('./node_modules') || !fs.existsSync('./node_modules/express')) { |
|
console.log('请先pnpm install -P安装') |
|
process.exit() |
|
} |
|
|
|
|
|
setLog() |
|
|
|
await redisInit() |
|
|
|
await checkRun() |
|
|
|
logger.info(`${cfg.package.name} 启动中...`) |
|
} |
|
|