mirror of
https://github.com/Jerryplusy/rc-plugin.git
synced 2025-10-14 08:09:19 +00:00
✨feat: 切换为生产方式启动
This commit is contained in:
parent
41352ce7e0
commit
26c9bca5c8
5
index.js
5
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 };
|
||||
|
5
server/next.config.js
Normal file
5
server/next.config.js
Normal file
@ -0,0 +1,5 @@
|
||||
export default {
|
||||
eslint: {
|
||||
ignoreDuringBuilds: true, // 构建时忽略 ESLint 错误
|
||||
},
|
||||
};
|
@ -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); // 正常退出
|
||||
|
Loading…
x
Reference in New Issue
Block a user