Skip to content

Commit a639018

Browse files
committed
build: 📝 Add version updater script for PHP files
1 parent 7bb59e0 commit a639018

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

package.json

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,21 @@
4040
"README.md",
4141
"CHANGELOG.md",
4242
"LICENSE"
43-
]
44-
}
43+
],
44+
"standard-version": {
45+
"bumpFiles": [
46+
{
47+
"filename": "package-lock.json",
48+
"type": "json"
49+
},
50+
{
51+
"filename": "package.json",
52+
"type": "json"
53+
},
54+
{
55+
"filename": "plugin.php",
56+
"updater": "wp-plugin-version-updater.js"
57+
}
58+
]
59+
}
60+
}

wp-plugin-version-updater.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module.exports.readVersion = function ( contents ) {
2+
const capturingRegex = /Version: (?<vnum>[0-9]\.[0-9]\.[0-9])/;
3+
const found = contents.match( capturingRegex );
4+
return found.groups.vnum;
5+
};
6+
7+
module.exports.writeVersion = function ( _contents, version ) {
8+
const regex = /Version: (?<vnum>[0-9]\.[0-9]\.[0-9])/;
9+
return _contents.replace( regex, 'Version: ' + version );
10+
};

0 commit comments

Comments
 (0)