Created
November 22, 2024 13:49
-
-
Save boxabirds/5a42a0c6fc13a413da7097b73264767d to your computer and use it in GitHub Desktop.
Autobump version patch (node script for bumping the version patch)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// track every build with a unique number | |
// e.g. in package.json … "build": "node scripts/increment-version-patch.js && <your normal build script>" | |
const fs = require('fs'); | |
const path = require('path'); | |
const packageJsonPath = path.join(__dirname, '..', 'package.json'); | |
const packageJson = require(packageJsonPath); | |
// Split version into major, minor, and patch | |
const [major, minor, patch] = packageJson.version.split('.').map(Number); | |
// Increment patch version | |
packageJson.version = `${major}.${minor}.${patch + 1}`; | |
// Write back to package.json | |
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2) + '\n'); | |
console.log(`Version incremented to ${packageJson.version}`); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment