Skip to content

Instantly share code, notes, and snippets.

@nicoavila
Created June 20, 2017 17:46
Show Gist options
  • Save nicoavila/706c430f1e78a63c39e5f21188368e53 to your computer and use it in GitHub Desktop.
Save nicoavila/706c430f1e78a63c39e5f21188368e53 to your computer and use it in GitHub Desktop.
Ionic 2 auto-upgrade app version
/*
* Instructions:
* -------------
*
* 1) Run npm install xml2js --save
*
* 2) Add in the script section if your package.json
* "scripts": {
* "clean": "ionic-app-scripts clean",
* "build": "ionic-app-scripts build",
* "lint": "ionic-app-scripts lint",
* "ionic:build": "ionic-app-scripts build",
* "ionic:serve": "ionic-app-scripts serve",
* "upgrade-version": "node upgrade-version.js"
* }
*
* 3) Create a upgrade-version.js in the root of the project
*
* 4) Paste the code below
*/
var fs = require('fs');
var xml2js = require('xml2js');
var parser = new xml2js.Parser();
var builder = new xml2js.Builder();
var version;
fs.readFile(__dirname + '/config.xml', function(err, data) {
parser.parseString(data, function (err, result) {
if (err) {
return console.log(err);
}
version = result['widget']['$'].version;
console.log("Actual version:" + version);
let versionSplit = version.split('.');
let newVersion = versionSplit[0] + '.' + versionSplit[1] + '.' + (parseInt(versionSplit[2]) + 1);
console.log("New version:" + newVersion);
result['widget']['$'].version = newVersion;
let xml = builder.buildObject(result);
fs.writeFile('config.xml', xml, function(err) {
if (err) {
return console.log(err);
}
console.log("config.xml file updated: " + newVersion);
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment