Created
March 12, 2020 13:52
-
-
Save kbkk/40427b8834dad774017cdbe35bae2ccf to your computer and use it in GitHub Desktop.
Bump package.json major version
This file contains 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
const fs = require( 'fs' ); | |
const semver = require( 'semver' ); | |
const cwd = process.cwd(); | |
const packageJsonPath = cwd + '/package.json'; | |
const content = fs.readFileSync( packageJsonPath, 'utf-8' ); | |
const [ fullMatch, currentVersion ] = content.match( /"version": "(.*)?"/ ) || []; | |
let newVersion; | |
if ( currentVersion.startsWith( '0' ) ) { | |
newVersion = semver.inc( currentVersion, 'minor' ); | |
} else { | |
newVersion = semver.inc( currentVersion, 'major' ); | |
} | |
const newContent = content.replace( fullMatch, `"version": "${ newVersion }"` ); | |
fs.writeFileSync( packageJsonPath, newContent ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment