Skip to content

Commit

Permalink
add version bump script and command
Browse files Browse the repository at this point in the history
  • Loading branch information
circlecube committed Dec 13, 2024
1 parent 6f64cc0 commit 7156c74
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
14 changes: 10 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,17 @@
"build": "wp-scripts build ./src/coming-soon.js",
"clean": "rm -rf ./assets/build && rm -rf ./assets/styles && rm -rf ./build",
"clean:node_modules": "rm -rf node_modules",
"format": "wp-scripts format ./src",
"start": "wp-scripts start ./src/coming-soon.js",
"start:local": "concurrently \"wp-scripts start ./src/coming-soon.js\" \"npm run json-server\"",
"lint:js": "wp-scripts lint-js ./src",
"lint:js:fix": "wp-scripts lint-js ./src --fix",
"json-server": "json-server --watch api.dev.json --port 3003"
"format": "wp-scripts format ./src",
"json-server": "json-server --watch api.dev.json --port 3003",
"set-version-bump": "node ./set-version-bump.js && npm i && rm -rf ./build && npm run build",
"start": "wp-scripts start ./src/coming-soon.js",
"start:local": "concurrently \"wp-scripts start ./src/coming-soon.js\" \"npm run json-server\""
},
"engines": {
"node": ">=20",
"npm": ">=10"
},
"devDependencies": {
"@wordpress/eslint-plugin": "^17.0.0",
Expand All @@ -35,6 +40,7 @@
"postcss-safe-important": "^1.2.1",
"prettier": "^3.0.3",
"prettier-plugin-tailwindcss": "^0.5.6",
"semver": "^7.6.3",
"tailwindcss": "^3.4.1",
"webpack-merge": "^5.10.0"
},
Expand Down
32 changes: 32 additions & 0 deletions set-version-bump.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
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;
fs.writeFileSync( packagefile, JSON.stringify( packageData, null, '\t' ) );

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 );
}

0 comments on commit 7156c74

Please sign in to comment.