Skip to content

Commit

Permalink
chore: calculate version number from packge.json and stick it into pl…
Browse files Browse the repository at this point in the history
…ugin.xml on semantic release
  • Loading branch information
amit-bansil committed Nov 16, 2016
1 parent 8585d6d commit fc3e109
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 13 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,20 @@ function genNpmPluginXML() {

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

});
// generate plugin.xml for local development
// here we reference the frameworks instead of all the files directly
function getDevPluginXML() {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"license": "MIT",
"scripts": {
"prerelease": "gulp prerelease",
"semantic-release": "semantic-release pre && npm publish && semantic-release post",
"semantic-release": "semantic-release pre && gulp update-plugin-xml-version && npm publish && semantic-release post",
"commit": "git-cz"
},
"dependencies": {
Expand Down

0 comments on commit fc3e109

Please sign in to comment.