39 lines
1.7 KiB
JavaScript
Executable File
39 lines
1.7 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
|
'use strict'
|
|
// Squirrel/NuGet require a strict SemVer MAJOR.MINOR.PATCH version. A 4th segment
|
|
// (e.g. 0.16.16.16) makes electron-forge's squirrel maker crash deep inside
|
|
// releasify ("not SemVer-compatible"). This runs before packaging and COERCES a
|
|
// non-SemVer package.json version to a valid 3-part one (the first three numbers),
|
|
// writing it back so the build never fails on version FORMAT again.
|
|
//
|
|
// NOTE: this only fixes the FORMAT. For an update to actually register, the
|
|
// version must still be GREATER than what's already published — so keep bumping
|
|
// the patch each release (0.16.17 -> 0.16.18 -> ...).
|
|
const fs = require('fs')
|
|
const path = require('path')
|
|
|
|
const pkgPath = path.join(__dirname, '..', 'package.json')
|
|
const raw = fs.readFileSync(pkgPath, 'utf8')
|
|
const v = (JSON.parse(raw).version || '').toString()
|
|
|
|
// Valid: exactly 3 numeric segments (plus optional -prerelease / +build).
|
|
if (/^\d+\.\d+\.\d+(?:[-+].*)?$/.test(v)) {
|
|
console.log(`[version] ${v} — SemVer OK`)
|
|
process.exit(0)
|
|
}
|
|
|
|
const nums = v.match(/\d+/g) || []
|
|
if (nums.length === 0) {
|
|
console.error(`[version] "${v}" has no numbers — set a version like 0.16.17 in package.json`)
|
|
process.exit(1)
|
|
}
|
|
|
|
const coerced = `${nums[0] || 0}.${nums[1] || 0}.${nums[2] || 0}`
|
|
// Targeted replace so the rest of package.json's formatting is untouched.
|
|
const out = raw.replace(/("version"\s*:\s*")[^"]*(")/, `$1${coerced}$2`)
|
|
fs.writeFileSync(pkgPath, out)
|
|
|
|
console.warn(`[version] "${v}" is NOT SemVer — coerced to "${coerced}" and updated package.json.`)
|
|
console.warn('[version] Squirrel requires MAJOR.MINOR.PATCH. If that\'s not newer than your')
|
|
console.warn('[version] published version, bump the patch so clients see the update.')
|