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

  1. import fs from 'node:fs'
  2. import path, { dirname } from 'node:path'
  3. import { fileURLToPath } from 'node:url'
  4. import semver from 'semver'
  5. const __filename = fileURLToPath(import.meta.url)
  6. const __dirname = dirname(__filename)
  7. const packagePath = path.resolve(__dirname, 'package.json')
  8. const packageJson = JSON.parse(fs.readFileSync(packagePath, 'utf-8'))
  9. // 读取命令行参数(默认使用 'patch')
  10. const versionType = process.argv[2] || 'patch'
  11. // 递增版本
  12. const newVersion = semver.inc(packageJson.version, versionType)
  13. if (!newVersion) {
  14. throw new Error(`Invalid version type: ${versionType}`)
  15. }
  16. packageJson.version = newVersion
  17. fs.writeFileSync(packagePath, JSON.stringify(packageJson, null, 2))
  18. console.log(`Version updated to: ${newVersion}`)