increment-version.js•973 B
#!/usr/bin/env node
// Auto-increment patch version in package.json (semantic versioning: major.minor.patch)
// If you want to bump minor or major automatically, extend with args or env flags.
import fs from 'fs';
import path from 'path';
const pkgPath = path.resolve(process.cwd(), 'package.json');
if (!fs.existsSync(pkgPath)) {
console.error('increment-version: package.json not found');
process.exit(1);
}
try {
const raw = fs.readFileSync(pkgPath, 'utf8');
const pkg = JSON.parse(raw);
const oldVersion = pkg.version || '0.0.0';
const parts = oldVersion.split('.').map(n => parseInt(n,10));
while (parts.length < 3) parts.push(0);
parts[2] += 1; // bump patch
const newVersion = parts.join('.');
pkg.version = newVersion;
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n');
console.log(`Version bumped: ${oldVersion} -> ${newVersion}`);
} catch (e) {
console.error('increment-version: failed', e.message);
process.exit(1);
}