diff --git a/index.js b/index.js index 56c4d14..c80cc07 100644 --- a/index.js +++ b/index.js @@ -1,7 +1,7 @@ import fs from "node:fs"; import path from "path"; import config from "./model/config.js"; -import { startNextJs } from "./start-nextjs.js"; +import { buildNextJs, startNextJs } from "./start-nextjs.js"; if (!global.segment) { global.segment = (await import("oicq")).segment } @@ -41,7 +41,8 @@ for (let i in files) { // 检查是否启动 webui if (isOpenWebUI) { - startNextJs(); + buildNextJs() + .then(() => startNextJs('start')) } export { apps }; diff --git a/server/next.config.js b/server/next.config.js new file mode 100644 index 0000000..2333c75 --- /dev/null +++ b/server/next.config.js @@ -0,0 +1,5 @@ +export default { + eslint: { + ignoreDuringBuilds: true, // 构建时忽略 ESLint 错误 + }, +}; diff --git a/start-nextjs.js b/start-nextjs.js index f09359f..519cfb4 100644 --- a/start-nextjs.js +++ b/start-nextjs.js @@ -4,13 +4,36 @@ logger.info(`[R插件][Next.js监测], 父进程 PID: ${process.pid}`); let childProcess = null; +// 构建应用程序 +export const buildNextJs = () => { + logger.info(logger.yellow('[R插件][Next.js监测],正在构建 Next.js 应用...')); + return new Promise((resolve, reject) => { + const buildProcess = spawn('pnpm', ['run', 'build'], { + cwd: './plugins/rconsole-plugin/server', + stdio: 'inherit', + }); + + buildProcess.on('close', (code) => { + if (code === 0) { + logger.info(logger.yellow('[R插件][Next.js监测],构建完成。')); + resolve(); + } else { + logger.error(`[R插件][Next.js监测],构建失败,退出码:${code}`); + reject(new Error('Build failed')); + } + }); + }); +}; + // 启动子进程运行 Next.js -export const startNextJs = () => { - logger.info(logger.yellow('[R插件][Next.js监测],启动 Next.js 进程...')); - // 加载名称 - childProcess = spawn('pnpm', ['run', 'dev'], { +export const startNextJs = (mode = 'start') => { + const script = mode === 'start' ? 'start' : 'dev'; + + logger.info(logger.yellow(`[R插件][Next.js监测],启动 Next.js ${mode} 进程...`)); + + childProcess = spawn('pnpm', ['run', script], { cwd: './plugins/rconsole-plugin', // 指定工作目录 - stdio: 'inherit' // 继承父进程的标准输入输出 + stdio: 'inherit', // 继承父进程的标准输入输出 }); // 子进程异常退出时捕获信号 @@ -30,6 +53,6 @@ const cleanup = () => { }; // 绑定父进程的退出信号 -process.on('SIGINT', cleanup); // Ctrl+C 信号 +process.on('SIGINT', cleanup); // Ctrl+C 信号 process.on('SIGTERM', cleanup); // kill 命令信号 -process.on('exit', cleanup); // 正常退出 +process.on('exit', cleanup); // 正常退出