diff --git a/cordova-app/config.xml b/cordova-app/config.xml index f49ccc3..d1d3d02 100644 --- a/cordova-app/config.xml +++ b/cordova-app/config.xml @@ -52,6 +52,7 @@ + diff --git a/cordova-app/package-lock.json b/cordova-app/package-lock.json index e50a6a1..5425306 100644 --- a/cordova-app/package-lock.json +++ b/cordova-app/package-lock.json @@ -1388,6 +1388,12 @@ "resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-0.0.3.tgz", "integrity": "sha1-o9XabNXAvAAI03I0u68b7WMFkQc=", "dev": true + }, + "xmldom": { + "version": "0.1.27", + "resolved": "https://registry.npmjs.org/xmldom/-/xmldom-0.1.27.tgz", + "integrity": "sha1-1QH5ezvbQDr4757MIFcxh6rawOk=", + "dev": true } } } diff --git a/cordova-app/package.json b/cordova-app/package.json index 7bed539..1989bba 100644 --- a/cordova-app/package.json +++ b/cordova-app/package.json @@ -26,6 +26,7 @@ "cordova-plugin-whitelist": "^1.3.3" }, "devDependencies": { - "http-server": "^0.11.1" + "http-server": "^0.11.1", + "xmldom": "^0.1.27" } -} \ No newline at end of file +} diff --git a/cordova-app/scripts/changeVersion.js b/cordova-app/scripts/changeVersion.js new file mode 100644 index 0000000..5ba8f66 --- /dev/null +++ b/cordova-app/scripts/changeVersion.js @@ -0,0 +1,37 @@ +module.exports = function(ctx) { + var configXmlHelper = require('./configXmlHelper'); + + var configXml = configXmlHelper.readConfigXML(); + var widget = configXml.getElementsByTagName("widget")[0]; + + var version = widget.getAttribute("version"); + var androidVersionCode = widget.getAttribute("android-versionCode"); + var iosCFBundleVersion = widget.getAttribute("ios-CFBundleVersion"); + + var versionSplit = version.split("."); + versionSplit[2] = parseInt(process.env.TRAVIS_BUILD_NUMBER || "0"); + + var newAndroidVersionCode = versionSplit[0] * 10000000 + versionSplit[1] * 10000 + versionSplit[2]; + var newVersion = versionSplit.join("."); + var newIosCFBundleVersion = newVersion; + + console.log("Version:", version); + console.log("android-versionCode:", androidVersionCode); + console.log("ios-CFBundleVersion:", iosCFBundleVersion); + + widget.setAttribute("version", newVersion); + widget.setAttribute("ios-CFBundleVersion", newIosCFBundleVersion); + widget.setAttribute("android-versionCode", newAndroidVersionCode); + + console.log("New Version:", widget.getAttribute("version")); + console.log("New android-versionCode:", widget.getAttribute("android-versionCode")); + console.log("New ios-CFBundleVersion:", widget.getAttribute("ios-CFBundleVersion")); + + configXmlHelper.writeConfigXML(configXml); +}; + +if (!require.main.loaded) { + module.exports({ + cmdLine: process.argv.join(" ") + }); +} diff --git a/cordova-app/scripts/configXmlHelper.js b/cordova-app/scripts/configXmlHelper.js new file mode 100644 index 0000000..56cf0ce --- /dev/null +++ b/cordova-app/scripts/configXmlHelper.js @@ -0,0 +1,19 @@ +var filePath = "config.xml"; +var xmldom = require('xmldom'); +var fs = require('fs'); + +module.exports = { + readConfigXML: function() { + var DOMParser = xmldom.DOMParser; + var xmlString = fs.readFileSync(filePath, "utf-8"); + + return new DOMParser().parseFromString(xmlString); + }, + + writeConfigXML: function (configXml) { + var XMLSerializer = xmldom.XMLSerializer; + var xmlString = new XMLSerializer().serializeToString(configXml); + + fs.writeFileSync(filePath, xmlString, 'utf8'); + } +};