chore(desktop-client): auto-bump version before packaging
Add scripts/bump-version.cjs and run it ahead of package:mac/win/linux so every build gets a fresh patch version. Supports DESKTOP_VERSION for an explicit version, or major/minor/patch via argument or DESKTOP_VERSION_BUMP. Version moves 0.1.0 -> 0.1.1. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
const fs = require('node:fs')
|
||||
const path = require('node:path')
|
||||
|
||||
const packageJsonPath = path.resolve(__dirname, '../package.json')
|
||||
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'))
|
||||
|
||||
const currentVersion = packageJson.version
|
||||
const requestedVersion = process.env.DESKTOP_VERSION
|
||||
const bumpType = process.argv[2] || process.env.DESKTOP_VERSION_BUMP || 'patch'
|
||||
|
||||
function assertVersion(version) {
|
||||
if (!/^\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?$/.test(version)) {
|
||||
throw new Error(`Invalid desktop version "${version}". Expected semver like 1.2.3.`)
|
||||
}
|
||||
}
|
||||
|
||||
function bump(version, type) {
|
||||
const match = /^(\d+)\.(\d+)\.(\d+)(?:[-+].*)?$/.exec(version)
|
||||
if (!match) {
|
||||
throw new Error(`Cannot bump invalid desktop version "${version}".`)
|
||||
}
|
||||
|
||||
const major = Number(match[1])
|
||||
const minor = Number(match[2])
|
||||
const patch = Number(match[3])
|
||||
|
||||
if (type === 'major') {
|
||||
return `${major + 1}.0.0`
|
||||
}
|
||||
|
||||
if (type === 'minor') {
|
||||
return `${major}.${minor + 1}.0`
|
||||
}
|
||||
|
||||
if (type === 'patch') {
|
||||
return `${major}.${minor}.${patch + 1}`
|
||||
}
|
||||
|
||||
assertVersion(type)
|
||||
return type
|
||||
}
|
||||
|
||||
assertVersion(currentVersion)
|
||||
|
||||
const nextVersion = requestedVersion || bump(currentVersion, bumpType)
|
||||
assertVersion(nextVersion)
|
||||
|
||||
packageJson.version = nextVersion
|
||||
fs.writeFileSync(packageJsonPath, `${JSON.stringify(packageJson, null, 2)}\n`)
|
||||
|
||||
console.log(`Desktop version bumped: ${currentVersion} -> ${nextVersion}`)
|
||||
Reference in New Issue
Block a user