|
@ -1,3 +1,4 @@ |
|
|
|
|
|
import { execSync } from 'node:child_process' |
|
|
import fs from 'node:fs' |
|
|
import fs from 'node:fs' |
|
|
import path, { dirname } from 'node:path' |
|
|
import path, { dirname } from 'node:path' |
|
|
import { fileURLToPath } from 'node:url' |
|
|
import { fileURLToPath } from 'node:url' |
|
@ -10,6 +11,7 @@ const packagePath = path.resolve(__dirname, 'package.json') |
|
|
const packageJson = JSON.parse(fs.readFileSync(packagePath, 'utf-8')) |
|
|
const packageJson = JSON.parse(fs.readFileSync(packagePath, 'utf-8')) |
|
|
|
|
|
|
|
|
// 读取命令行参数(默认使用 'patch')
|
|
|
// 读取命令行参数(默认使用 'patch')
|
|
|
|
|
|
// eslint-disable-next-line node/prefer-global/process
|
|
|
const versionType = process.argv[2] || 'patch' |
|
|
const versionType = process.argv[2] || 'patch' |
|
|
|
|
|
|
|
|
// 递增版本
|
|
|
// 递增版本
|
|
@ -21,3 +23,21 @@ if (!newVersion) { |
|
|
packageJson.version = newVersion |
|
|
packageJson.version = newVersion |
|
|
fs.writeFileSync(packagePath, JSON.stringify(packageJson, null, 2)) |
|
|
fs.writeFileSync(packagePath, JSON.stringify(packageJson, null, 2)) |
|
|
console.log(`Version updated to: ${newVersion}`) |
|
|
console.log(`Version updated to: ${newVersion}`) |
|
|
|
|
|
|
|
|
|
|
|
// 新增:自动提交 package.json 到远程仓库
|
|
|
|
|
|
try { |
|
|
|
|
|
// 将 package.json 添加到暂存区
|
|
|
|
|
|
execSync('git add package.json') |
|
|
|
|
|
console.log('Added package.json to staging area.') |
|
|
|
|
|
|
|
|
|
|
|
// 提交更改
|
|
|
|
|
|
execSync(`git commit -m "fix: Update version to V${newVersion}"`) |
|
|
|
|
|
console.log(`Committed changes with message: Update version to ${newVersion}`) |
|
|
|
|
|
|
|
|
|
|
|
// 推送到远程仓库
|
|
|
|
|
|
execSync('git push') |
|
|
|
|
|
console.log('Pushed changes to remote repository.') |
|
|
|
|
|
} |
|
|
|
|
|
catch (error) { |
|
|
|
|
|
console.error('Failed to commit and push changes:', error.message) |
|
|
|
|
|
} |