forked from gzt/A8000
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
23 lines
766 B
23 lines
766 B
import fs from 'node:fs'
|
|
import path, { dirname } from 'node:path'
|
|
import { fileURLToPath } from 'node:url'
|
|
import semver from 'semver'
|
|
|
|
const __filename = fileURLToPath(import.meta.url)
|
|
const __dirname = dirname(__filename)
|
|
|
|
const packagePath = path.resolve(__dirname, 'package.json')
|
|
const packageJson = JSON.parse(fs.readFileSync(packagePath, 'utf-8'))
|
|
|
|
// 读取命令行参数(默认使用 'patch')
|
|
const versionType = process.argv[2] || 'patch'
|
|
|
|
// 递增版本
|
|
const newVersion = semver.inc(packageJson.version, versionType)
|
|
if (!newVersion) {
|
|
throw new Error(`Invalid version type: ${versionType}`)
|
|
}
|
|
|
|
packageJson.version = newVersion
|
|
fs.writeFileSync(packagePath, JSON.stringify(packageJson, null, 2))
|
|
console.log(`Version updated to: ${newVersion}`)
|