From 6b2e4a073844f44d400236c75f42b2b431cc1efe Mon Sep 17 00:00:00 2001 From: ningmengchongshui <916415899@qq.com> Date: Mon, 10 Jun 2024 00:37:59 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E8=BF=9B=E7=A8=8B?= =?UTF-8?q?=E6=89=98=E7=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 22 ++++++++-------------- index.js | 25 +++++++++++++++++++++++++ package.json | 22 +++++++++++----------- pm2.config.cjs | 12 ++++++++++++ 4 files changed, 56 insertions(+), 25 deletions(-) create mode 100644 index.js create mode 100644 pm2.config.cjs diff --git a/README.md b/README.md index 6cb1495..ee0c09d 100644 --- a/README.md +++ b/README.md @@ -10,9 +10,9 @@ > 必要环境 Windows/Linux + Chrome/Chromium/Edge -> 必要环境 18.18.2>Node.js>16.14.0 + Redis>5.0.0 +> 必要环境 Node.js>16.14.0 + Redis>5.0.0 -如果你的系统不支持18.18.2版本,最低能下载16.14.0版本,这是最新的puppeteer版本限制。 +推荐使用`18.18.2`版本,如果系统不支持,最低要求`16.14.0`,这是新版`puppeteer`的限制 ## 开发者 @@ -49,29 +49,23 @@ pnpm install - 启动 ```sh -npm run ts:app +npm run app ``` - 重新登录 ```sh -npm run ts:app login +npm run app login ``` -> 暂不支持PM2托管进程 - -## Unknown file ".ts" - -node >= 20.0.0 - -- 启动 +- 进程托管 ```sh -npm run latest:app +npm run start ``` -- 重新登录 +- 杀死进程 ```sh -npm run latest:app login +npm run kill ``` diff --git a/index.js b/index.js new file mode 100644 index 0000000..5a04b67 --- /dev/null +++ b/index.js @@ -0,0 +1,25 @@ +import { spawn } from 'child_process' +const argv = [...process.argv].splice(2) +const argvs = argv.join(' ').replace(/(\S+\.js|\S+\.ts)/g, '') +/** + * *************** + * 启动内部运行脚本 + * *************** + */ +const child = spawn( + 'node --no-warnings=ExperimentalWarning --loader ts-node/esm src/main.ts', + argvs.split(' '), + { + shell: true, + stdio: 'inherit' + } +) +/** + * ************* + * exit + * ************* + */ +process.on('SIGINT', () => { + if (child.pid) process.kill(child.pid) + if (process.pid) process.exit() +}) diff --git a/package.json b/package.json index c31eb7d..7a47f1c 100644 --- a/package.json +++ b/package.json @@ -3,19 +3,19 @@ "version": "4.0.0-rc.0", "author": "Yoimiya-Kokomi, Le-niao", "description": "QQ Group Bot", - "main": "app.js", + "main": "./index.js", "type": "module", "scripts": { - "app": "node .", - "login": "node . login", - "start": "pm2 start ./config/pm2/pm2.json", - "stop": "pm2 stop ./config/pm2/pm2.json", - "restart": "pm2 restart ./config/pm2/pm2.json", - "ts:app": "ts-node src/main.ts", - "ts:login": "ts-node src/main.ts login", - "ts:build": "rollup --config rollup.config.js", - "latest:app": "node --no-warnings=ExperimentalWarning --loader ts-node/esm src/main.ts", - "latest:login": "node --no-warnings=ExperimentalWarning --loader ts-node/esm src/main.ts login", + "app": "node index.js", + "login": "node index.js login", + "build": "rollup --config rollup.config.js", + "start": "pm2 startOrRestart pm2.config.cjs", + "stop": "pm2 stop pm2.config.cjs", + "delete": "pm2 delete pm2.config.cjs", + "kill": "pm2 kill", + "logs": "pm2 logs", + "monit": "pm2 monit", + "pm2": "pm2", "docs": "typedoc --options typedoc.json", "format": "prettier --write .", "prepare": "husky" diff --git a/pm2.config.cjs b/pm2.config.cjs new file mode 100644 index 0000000..1729e56 --- /dev/null +++ b/pm2.config.cjs @@ -0,0 +1,12 @@ +const argv = [...process.argv].slice(4) +module.exports = { + apps: [ + { + name: 'Miao-Yunzai', + script: './index.js', + args: argv, + max_memory_restart: '512M', + restart_delay: 60000 + } + ] +}