消毒机设备
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.

43 lines
1.4 KiB

  1. import { execSync } from 'node:child_process' // 引入 child_process 模块用于执行 Git 命令
  2. import fs from 'node:fs'
  3. import path, { dirname } from 'node:path'
  4. import { fileURLToPath } from 'node:url'
  5. import semver from 'semver'
  6. const __filename = fileURLToPath(import.meta.url)
  7. const __dirname = dirname(__filename)
  8. const packagePath = path.resolve(__dirname, 'package.json')
  9. const packageJson = JSON.parse(fs.readFileSync(packagePath, 'utf-8'))
  10. // 读取命令行参数(默认使用 'patch')
  11. // eslint-disable-next-line node/prefer-global/process
  12. const versionType = process.argv[2] || 'patch'
  13. // 递增版本
  14. const newVersion = semver.inc(packageJson.version, versionType)
  15. if (!newVersion) {
  16. throw new Error(`Invalid version type: ${versionType}`)
  17. }
  18. packageJson.version = newVersion
  19. fs.writeFileSync(packagePath, JSON.stringify(packageJson, null, 2))
  20. console.log(`Version updated to: ${newVersion}`)
  21. // 新增:自动提交 package.json 到远程仓库
  22. try {
  23. // 将 package.json 添加到暂存区
  24. execSync('git add package.json')
  25. console.log('Added package.json to staging area.')
  26. // 提交更改
  27. execSync(`git commit -m "fix: Update version to V${newVersion}"`)
  28. console.log(`Committed changes with message: Update version to ${newVersion}`)
  29. // 推送到远程仓库
  30. execSync('git push')
  31. console.log('Pushed changes to remote repository.')
  32. }
  33. catch (error) {
  34. console.error('Failed to commit and push changes:', error.message)
  35. }