Skip to content

Instantly share code, notes, and snippets.

@boxabirds
Created November 22, 2024 13:49
Show Gist options
  • Save boxabirds/5a42a0c6fc13a413da7097b73264767d to your computer and use it in GitHub Desktop.
Save boxabirds/5a42a0c6fc13a413da7097b73264767d to your computer and use it in GitHub Desktop.
Autobump version patch (node script for bumping the version patch)
// 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