Skip to content

Commit be4df83

Browse files
authored
Merge pull request #240 from BranchMetrics/chore/calculate-plugin.xml-version-number
chore: calculate version number from packge.json and stick it into plugin.xml on semantic release
2 parents 8585d6d + c45824a commit be4df83

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

gulpfile.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,20 @@ function genNpmPluginXML() {
3838

3939
fs.writeFileSync('plugin.xml', xml);
4040
};
41+
// first match only!
42+
var PLUGIN_XML_VERSION_REGEX = /^\s*version=\"[\d\.]*\"\>$/m;
43+
gulp.task('update-plugin-xml-version', () => {
44+
var versionNumber = require('./package.json').version;
45+
// this will break if plugin.xml is not formatted exactly as we expect
46+
// so you might end up needing to fix the regex
47+
for (target of [ '.xml', '.template.xml' ]) {
48+
var pluginXML = fs.readFileSync('plugin' + target, 'utf8');
49+
var newVersionXML = ` version="${versionNumber}">`;
50+
pluginXML = pluginXML.replace(PLUGIN_XML_VERSION_REGEX, newVersionXML);
51+
fs.writeFileSync('plugin' + target, pluginXML);
52+
}
4153

54+
});
4255
// generate plugin.xml for local development
4356
// here we reference the frameworks instead of all the files directly
4457
function getDevPluginXML() {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"license": "MIT",
3333
"scripts": {
3434
"prerelease": "gulp prerelease",
35-
"semantic-release": "semantic-release pre && npm publish && semantic-release post",
35+
"semantic-release": "semantic-release pre && gulp update-plugin-xml-version && npm publish && semantic-release post",
3636
"commit": "git-cz"
3737
},
3838
"dependencies": {

0 commit comments

Comments
 (0)