Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Fixes #40 - added ability to set application id, name and version in config.xml #69

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion Tasks/CordovaBuild/lib/cordova-task.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -391,6 +392,7 @@ function execBuild(code) {

return Q();
}).then(function () {
changeCordovaConfig();
return teambuild.buildProject(platform, buildArgs)
}).fin(function () {
// Remove xcconfig hook
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion Tasks/CordovaBuild/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
32 changes: 32 additions & 0 deletions Tasks/CordovaBuild/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down