From 321c6ec0e1e0a12248247baa4bfc282fe83eb42d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=F0=9F=8C=8C?= Date: Tue, 22 Aug 2023 22:50:35 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=20pnpm=20log?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tools/name.js | 35 +++++++++++++++++++++++++++++++++++ package.json | 4 ++-- 2 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 lib/tools/name.js diff --git a/lib/tools/name.js b/lib/tools/name.js new file mode 100644 index 0000000..d4ff2f2 --- /dev/null +++ b/lib/tools/name.js @@ -0,0 +1,35 @@ +import fs from "node:fs" +import childProcess from "child_process" + +const _path = process.cwd() + +fs.readFile(`${_path}/config/pm2/pm2.json`, `utf8`, (err, data) => { + if (err) { + console.log('pm2.json文件读取错误:', err) + return + } + + try { + const config = JSON.parse(data) + if (config.apps && config.apps.length > 0 && config.apps[0].name) { + const appName = config.apps[0].name + console.log(config.apps[0].name) + runPm2Logs(appName) + } else { + console.log('读取失败:无法在pm2.json中找到name数组') + } + } catch (parseError) { + console.log('读取失败:json文件解析发生了错误', parseError) + } +}) + +function runPm2Logs(appName) { + const command = process.platform === 'win32' ? 'pm2.cmd' : 'pm2' + const args = ['logs', '--lines', '400', appName] + const pm2LogsProcess = childProcess.spawn(command, args, { stdio: 'inherit' }) + pm2LogsProcess.on('exit', (code) => { + if (code !== 0) { + console.error(`pm2 logs process exited with code ${code}`) + } + }) +} \ No newline at end of file diff --git a/package.json b/package.json index 2f7a206..d8e5b95 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "start": "pm2 start ./config/pm2/pm2.json", "stop": "pm2 stop ./config/pm2/pm2.json", "restart": "pm2 restart ./config/pm2/pm2.json", - "log": "pm2 logs --lines 400 TRSS-Yunzai" + "log": "node ./lib/tools/name.js" }, "dependencies": { "art-template": "^4.13.2", @@ -43,7 +43,7 @@ "eslint": "^8.47.0", "eslint-config-standard": "^17.1.0", "eslint-plugin-import": "^2.28.1", - "eslint-plugin-n": "^16.0.1", + "eslint-plugin-n": "^16.0.2", "eslint-plugin-promise": "^6.1.1" }, "imports": {