diff --git a/package.json b/package.json index 700d86b20..6357595ee 100644 --- a/package.json +++ b/package.json @@ -87,6 +87,7 @@ "php-deps": "composer install --no-dev --optimize-autoloader", "postprepare": "npm run set-wp-version", "prebuild:cleanup": "rm -rf ./build ./bluehost-wordpress-plugin ./bluehost-wordpress-plugin.zip ./vendor", + "set-version-bump": "node ./set-version-bump.js && npm i && rm -rf ./build && npm run build && composer run i18n", "set-wp-version": "node ./set-latest-wp-version.js", "simulate-runner-build": "npm run prebuild:cleanup && npm i --legacy-peer-deps && npm run php-deps && npm run build && npm run create:dist && npm run create:zip", "srb": "npm run simulate-runner-build", diff --git a/set-version-bump.js b/set-version-bump.js new file mode 100644 index 000000000..bd3c0b94c --- /dev/null +++ b/set-version-bump.js @@ -0,0 +1,32 @@ +const fs = require( 'fs' ); +const semver = require( 'semver' ); +const packagefile = './package.json'; +const pluginfile = './bluehost-wordpress-plugin.php'; + +if ( fs.existsSync( packagefile ) && fs.existsSync( pluginfile ) ) { + const packageData = require( packagefile ); + const currentVersion = packageData.version; + let type = process.argv[ 2 ]; + if ( ! [ 'major', 'minor', 'patch' ].includes( type ) ) { + type = 'patch'; + } + + const newVersion = semver.inc( packageData.version, type ); + packageData.version = newVersion; + fs.writeFileSync( packagefile, JSON.stringify( packageData, null, 4 ) ); + + fs.readFile( pluginfile, 'utf8', function ( err, data ) { + if ( err ) { + return console.log( err ); + } + const result = data.replaceAll( currentVersion, newVersion ); + + fs.writeFile( pluginfile, result, 'utf8', function ( err ) { + if ( err ) { + return console.log( err ); + } + } ); + } ); + + console.log( 'Version updated', currentVersion, '=>', newVersion ); +}