Skip to content

Commit

Permalink
Merge pull request #124 from newfold-labs/add/version-bump-script
Browse files Browse the repository at this point in the history
Add/version bump script
  • Loading branch information
circlecube authored Jan 22, 2025
2 parents f54e2f4 + 597c659 commit 368b604
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
2 changes: 1 addition & 1 deletion bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
return;
}

define( 'NFD_DATA_MODULE_VERSION', '2.6.8' );
define( 'NFD_DATA_MODULE_VERSION', '2.6.9' );

if ( function_exists( 'is_admin' ) && is_admin() ) {
$upgrade_handler = new UpgradeHandler(
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
{
"name": "wp-module-data",
"version": "1.0.0",
"version": "2.6.9",
"description": "",
"main": "index.js",
"directories": {
"test": "tests"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"set-version-bump": "node ./set-version-bump.js && npm ci"
},
"keywords": [],
"author": "",
"license": "GPL-2.0-or-later",
"devDependencies": {
"@wordpress/env": "^10.1"
}
}
}
35 changes: 35 additions & 0 deletions set-version-bump.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const fs = require( 'fs' );
const semver = require( 'semver' );
const packagefile = './package.json';
const pluginfile = './bootstrap.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;

// update version in package file
fs.writeFileSync( packagefile, JSON.stringify( packageData, null, 2 ) );

fs.readFile( pluginfile, 'utf8', function ( err, data ) {
if ( err ) {
return console.log( err );
}
const result = data.replaceAll( currentVersion, newVersion );

// update version in php file
fs.writeFile( pluginfile, result, 'utf8', function ( err ) {
if ( err ) {
return console.log( err );
}
} );
} );

console.log( 'Version updated', currentVersion, '=>', newVersion );
}

0 comments on commit 368b604

Please sign in to comment.