feat: 添加 npm patch 命令以自动更新补丁版本
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user