From a74b984d95c4ab1270c76fc38539d6b418b331d1 Mon Sep 17 00:00:00 2001 From: abearxiong Date: Tue, 3 Feb 2026 03:01:25 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=20npm=20patch=20?= =?UTF-8?q?=E5=91=BD=E4=BB=A4=E4=BB=A5=E8=87=AA=E5=8A=A8=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E8=A1=A5=E4=B8=81=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/command/npm.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/command/npm.ts b/src/command/npm.ts index cca45e7..5e65c5c 100644 --- a/src/command/npm.ts +++ b/src/command/npm.ts @@ -210,5 +210,29 @@ const install = new Command('install') }); command.addCommand(install); +// npm patch +const patch = new Command('patch').description('npm patch 发布补丁版本').action(async () => { + const cwd = process.cwd(); + const packageJson = path.resolve(cwd, 'package.json'); + if (fileIsExist(packageJson)) { + const pkg = fs.readFileSync(packageJson, 'utf-8'); + const pkgJson = parseIfJson(pkg); + const version = pkgJson?.version as string; + if (version) { + const versionArr = String(version).split('.'); + if (versionArr.length === 3) { + const patchVersion = Number(versionArr[2]) + 1; + const newVersion = `${versionArr[0]}.${versionArr[1]}.${patchVersion}`; + pkgJson.version = newVersion; + fs.writeFileSync(packageJson, JSON.stringify(pkgJson, null, 2)); + console.log(chalk.green(`${pkgJson?.name} 更新到版本: ${newVersion}`)); + } + } + } +}); +command.addCommand(patch); + // program 添加npm 的命令 program.addCommand(command); + +