From 15b07416aae503ffc78eb1d427ed83f85ccd774d Mon Sep 17 00:00:00 2001 From: "Pavel Yakovlev (Akvelon)" Date: Thu, 11 May 2017 16:36:37 +0300 Subject: [PATCH] - added ability to set application id, name and version in config.xml in CordovaBuild --- Tasks/CordovaBuild/lib/cordova-task.js | 31 ++++++++++++++++++++++++- Tasks/CordovaBuild/package.json | 3 ++- Tasks/CordovaBuild/task.json | 32 ++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 2 deletions(-) diff --git a/Tasks/CordovaBuild/lib/cordova-task.js b/Tasks/CordovaBuild/lib/cordova-task.js index b95e680..5dc4d3c 100644 --- a/Tasks/CordovaBuild/lib/cordova-task.js +++ b/Tasks/CordovaBuild/lib/cordova-task.js @@ -10,7 +10,8 @@ var path = require('path'), glob = require('glob'), xcutils = require('./xcode-task-utils.js'), teambuild = require('taco-team-build'), - shelljs = require('shelljs'); + shelljs = require('shelljs'), + ConfigParser = require('cordova-common').ConfigParser; // Globals - Easy way to have data available across promises. @@ -391,6 +392,7 @@ function execBuild(code) { return Q(); }).then(function () { + changeCordovaConfig(); return teambuild.buildProject(platform, buildArgs) }).fin(function () { // Remove xcconfig hook @@ -406,6 +408,33 @@ function execBuild(code) { }); } +function changeCordovaConfig() { + var config = new ConfigParser(path.join(cwd, 'config.xml')); + if (process.env['INPUT_APPID']) { + config.setPackageName(process.env['INPUT_APPID']); + console.log("Application id: " + process.env['INPUT_APPID']); + } + if (process.env['INPUT_APPNAME']) { + config.setName(process.env['INPUT_APPNAME']); + console.log("Application name: " + process.env['INPUT_APPNAME']); + } + if (process.env['INPUT_VERSIONBUILDAUTOINCREMENT']) { + var arrayVersion = /(\d).(\d).(\d)/.exec(config.version()); + if (!arrayVersion) { + return; + } + arrayVersion[3]++; + arrayVersion.splice(0, 1); + var newVersion = arrayVersion.join('.'); + process.env['INPUT_VERSIONBUILD'] = newVersion; + } + if (process.env['INPUT_VERSIONBUILD']) { + config.setVersion(process.env['INPUT_VERSIONBUILD']); + console.log("Application version: " + process.env['INPUT_VERSIONBUILD']); + } + config.write(); +} + function stripNewerAndroidArgs(args) { // For versions of cordova earlier than 4.0.0, the android build will reject all args except: // --debug, --release, --ant, --gradle, and --nobuild diff --git a/Tasks/CordovaBuild/package.json b/Tasks/CordovaBuild/package.json index 2098cbc..6d0ca39 100644 --- a/Tasks/CordovaBuild/package.json +++ b/Tasks/CordovaBuild/package.json @@ -11,6 +11,7 @@ "semver": "^5.0.3", "shelljs": "^0.7.0", "taco-team-build": "^0.2.5", - "vsts-task-lib": "^0.8.2" + "vsts-task-lib": "^0.8.2", + "cordova-common": "^2.0.3" } } diff --git a/Tasks/CordovaBuild/task.json b/Tasks/CordovaBuild/task.json index 1bdb129..3f4cd81 100644 --- a/Tasks/CordovaBuild/task.json +++ b/Tasks/CordovaBuild/task.json @@ -265,6 +265,38 @@ "required":false, "helpMarkDown": "Build for a emulator or simulator instead of devices.", "groupName":"advanced" + }, + { + "name": "appId", + "type": "string", + "label": "Application Id", + "required": false, + "helpMarkDown": "Id application to be compiled (Example: \"io.cordova.myapp12345\"). If it is empty, it will not be changed.", + "groupName":"advanced" + }, + { + "name": "appName", + "type": "string", + "label": "Application name", + "required": false, + "helpMarkDown": "Name of application to be compiled. If it is empty, it will not be changed.", + "groupName":"advanced" + }, + { + "name": "versionBuild", + "type": "string", + "label": "Build version", + "required": false, + "helpMarkDown": "Full build version application (Example: \"0.0.1\"). If it is empty, it will not be changed.", + "groupName":"advanced" + }, + { + "name": "versionBuildAutoincrement", + "type": "boolean", + "label": "Autoincrement build version", + "required": false, + "helpMarkDown": "Autoincrement build version application", + "groupName":"advanced" } ], "execution": {