Skip to content

Commit 0af8fe2

Browse files
committed
normalise package.json with bump script
1 parent 5c156e0 commit 0af8fe2

File tree

3 files changed

+127
-57
lines changed

3 files changed

+127
-57
lines changed

package.json

Lines changed: 59 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,60 @@
11
{
2-
"name": "codeb-feature-flags",
3-
"version": "0.2.1",
4-
"description": "Allows developers to enable / disable features based on flags.",
5-
"scripts": {
6-
"start": "wp-scripts start",
7-
"build": "wp-scripts build",
8-
"lint:js": "wp-scripts lint-js",
9-
"lint:js:fix": "wp-scripts lint-js --fix",
10-
"lint:css": "wp-scripts lint-style",
11-
"lint:css:fix": "npm run lint:css -- --fix",
12-
"test:js": "wp-scripts test-unit-js",
13-
"test:watch": "wp-scripts test-unit-js --watch",
14-
"prepare": "husky",
15-
"wp-env": "wp-env start",
16-
"test:e2e": "npx playwright test --reporter=list"
17-
},
18-
"devDependencies": {
19-
"@playwright/test": "^1.42.0",
20-
"@testing-library/jest-dom": "^6.4.2",
21-
"@testing-library/react": "14.2.1",
22-
"@types/jest": "^29.5.12",
23-
"@types/node": "^20.11.20",
24-
"@types/react-syntax-highlighter": "^15.5.11",
25-
"@types/wordpress__components": "^23.0.11",
26-
"@wordpress/e2e-test-utils-playwright": "^0.20.0",
27-
"@wordpress/env": "^9.4.0",
28-
"@wordpress/eslint-plugin": "^17.9.0",
29-
"@wordpress/scripts": "^27.3.0",
30-
"eslint": "^8.57.0",
31-
"eslint-import-resolver-alias": "^1.1.2",
32-
"eslint-plugin-cypress": "^2.15.1",
33-
"eslint-plugin-import": "^2.29.1",
34-
"husky": "^9.0.11",
35-
"jest-environment-jsdom": "^29.7.0",
36-
"prettier": "^3.2.5"
37-
},
38-
"keywords": [],
39-
"author": "Mohan Raj <https://mohanraj.dev>",
40-
"license": "ISC",
41-
"dependencies": {
42-
"@wordpress/api-fetch": "^6.48.0",
43-
"@wordpress/components": "^27.0.0",
44-
"@wordpress/data": "^9.22.0",
45-
"@wordpress/dom-ready": "^3.52.0",
46-
"@wordpress/hooks": "^3.52.0",
47-
"@wordpress/i18n": "^4.52.0",
48-
"@wordpress/notices": "^4.20.0",
49-
"dotenv": "^16.4.5",
50-
"react": "18.2.0",
51-
"react-dom": "18.2.0",
52-
"react-syntax-highlighter": "^15.5.0",
53-
"react-test-renderer": "^18.2.0",
54-
"ts-loader": "^9.5.1",
55-
"typescript": "^5.3.3"
56-
}
57-
}
2+
"name": "codeb-feature-flags",
3+
"version": "0.3.0",
4+
"description": "Allows developers to enable / disable features based on flags.",
5+
"license": "ISC",
6+
"author": "Mohan Raj <https://mohanraj.dev>",
7+
"scripts": {
8+
"build": "wp-scripts build",
9+
"lint:css": "wp-scripts lint-style",
10+
"lint:css:fix": "npm run lint:css -- --fix",
11+
"lint:js": "wp-scripts lint-js",
12+
"lint:js:fix": "wp-scripts lint-js --fix",
13+
"prepare": "husky",
14+
"start": "wp-scripts start",
15+
"test:e2e": "npx playwright test --reporter=list",
16+
"test:js": "wp-scripts test-unit-js",
17+
"test:watch": "wp-scripts test-unit-js --watch",
18+
"version:major": "node ./scripts/version major",
19+
"version:minor": "node ./scripts/version minor",
20+
"version:patch": "node ./scripts/version patch",
21+
"wp-env": "wp-env start"
22+
},
23+
"dependencies": {
24+
"@wordpress/api-fetch": "^6.48.0",
25+
"@wordpress/components": "^27.0.0",
26+
"@wordpress/data": "^9.22.0",
27+
"@wordpress/dom-ready": "^3.52.0",
28+
"@wordpress/hooks": "^3.52.0",
29+
"@wordpress/i18n": "^4.52.0",
30+
"@wordpress/notices": "^4.20.0",
31+
"dotenv": "^16.4.5",
32+
"react": "18.2.0",
33+
"react-dom": "18.2.0",
34+
"react-syntax-highlighter": "^15.5.0",
35+
"react-test-renderer": "^18.2.0",
36+
"ts-loader": "^9.5.1",
37+
"typescript": "^5.3.3"
38+
},
39+
"devDependencies": {
40+
"@playwright/test": "^1.42.0",
41+
"@testing-library/jest-dom": "^6.4.2",
42+
"@testing-library/react": "14.2.1",
43+
"@types/jest": "^29.5.12",
44+
"@types/node": "^20.11.20",
45+
"@types/react-syntax-highlighter": "^15.5.11",
46+
"@types/wordpress__components": "^23.0.11",
47+
"@wordpress/e2e-test-utils-playwright": "^0.20.0",
48+
"@wordpress/env": "^9.4.0",
49+
"@wordpress/eslint-plugin": "^17.9.0",
50+
"@wordpress/scripts": "^27.3.0",
51+
"eslint": "^8.57.0",
52+
"eslint-import-resolver-alias": "^1.1.2",
53+
"eslint-plugin-cypress": "^2.15.1",
54+
"eslint-plugin-import": "^2.29.1",
55+
"husky": "^9.0.11",
56+
"jest-environment-jsdom": "^29.7.0",
57+
"prettier": "^3.2.5"
58+
},
59+
"keywords": []
60+
}

plugin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* Plugin Name: Feature Flags
1010
* Plugin URI: https://github.com/codebtech/wp-feature-flags
1111
* Description: Allows developers to enable / disable features based on flags.
12-
* Version: 0.2.1
12+
* Version: 0.3.0
1313
* Requires at least: 6.4
1414
* Requires PHP: 8.1
1515
* Author: Mohan Raj

scripts/version.js

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/* eslint-disable @typescript-eslint/no-var-requires */
2+
const fs = require('fs');
3+
const path = require('path');
4+
const package = require('../package.json');
5+
6+
const packagePath = path.join(process.cwd(), 'package.json');
7+
const phpPath = path.join(process.cwd(), 'plugin.php');
8+
9+
const bumpTypes = ['patch', 'minor', 'major'];
10+
11+
const fsOpts = { encoding: 'utf-8' };
12+
13+
const getNewVersion = () => {
14+
const bumpType = process.argv[2];
15+
let [major, minor, patch] = package.version
16+
.split('.')
17+
.map((num) => parseInt(num, 10));
18+
19+
if (!bumpTypes.includes(bumpType)) {
20+
throw new Error(`Invalid bump type: ${bumpType}`);
21+
}
22+
23+
if (bumpType === 'patch') {
24+
patch += 1;
25+
}
26+
27+
if (bumpType === 'minor') {
28+
patch = 0;
29+
minor += 1;
30+
}
31+
32+
if (bumpType === 'major') {
33+
patch = 0;
34+
minor = 0;
35+
major += 1;
36+
}
37+
38+
return `${major}.${minor}.${patch}`;
39+
};
40+
41+
(async () => {
42+
const previousVersion = package.version;
43+
const newVersion = getNewVersion();
44+
45+
const newPackage = JSON.stringify(
46+
{
47+
...package,
48+
version: newVersion,
49+
},
50+
null,
51+
2
52+
);
53+
54+
const [php, css] = await Promise.all([
55+
fs.promises.readFile(phpPath, fsOpts),
56+
]);
57+
58+
const newPHP = php.replace(new RegExp(previousVersion, 'g'), newVersion);
59+
60+
await Promise.all([
61+
fs.promises.writeFile(packagePath, newPackage, fsOpts),
62+
fs.promises.writeFile(phpPath, newPHP, fsOpts),
63+
]);
64+
65+
// eslint-disable-next-line no-console
66+
console.log(`Version bumped to: ${newVersion}`);
67+
})();

0 commit comments

Comments
 (0)