Skip to content

Commit

Permalink
Merge pull request #6 from tmarkovski/master
Browse files Browse the repository at this point in the history
Ability to configure the tag names read from the project file
  • Loading branch information
MrTarantula authored Nov 12, 2018
2 parents 386d554 + 3096762 commit b841230
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
23 changes: 23 additions & 0 deletions versionintovariables/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@
"Minor": 0,
"Patch": 0
},
"groups": [
{
"name": "advanced",
"displayName": "Advanced",
"isExpanded": false
}
],
"demands": [],
"inputs": [{
"name": "path",
Expand All @@ -24,6 +31,22 @@
"type": "string",
"label": "Variables Prefix",
"helpMarkDown": "Prefix to append to variables, if desired."
},
{
"name": "versionTag",
"type": "string",
"groupName": "advanced",
"defaultValue": "ApplicationVersion",
"label": "Version Tag Name",
"helpMarkDown": "Name of the tag that holds the version information in your project file."
},
{
"name": "revisionTag",
"type": "string",
"groupName": "advanced",
"defaultValue": "ApplicationRevision",
"label": "Revision Tag Name",
"helpMarkDown": "Name of the tag that holds the revison information in your project file."
}
],
"instanceNameFormat": "Get Application Version as variables from $(path)",
Expand Down
6 changes: 4 additions & 2 deletions versionintovariables/versionintovariables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@ const workingDir: string = tl.getVariable('System.DefaultWorkingDirectory');
const projectFilePath: string = tl.getPathInput('path', true, true);
let prefix: string = tl.getInput('prefix');
prefix = prefix ? prefix + '.' : '';
let versionTagName: string = tl.getInput('versionTag');
let revisionTagName: string = tl.getInput('revisionTag');
async function run() {
try {
tl.debug(`File Path: ${projectFilePath}`);

const projFiles = tl.findMatch(workingDir, projectFilePath);
projFiles.forEach((file) => {
const doc: Document = new Parser.DOMParser().parseFromString(fs.readFileSync(file, { encoding: 'utf8' }));
const versionElem = doc.getElementsByTagName('ApplicationVersion').item(0);
const revisionElem = doc.getElementsByTagName('ApplicationRevision').item(0);
const versionElem = doc.getElementsByTagName(versionTagName).item(0);
const revisionElem = doc.getElementsByTagName(revisionTagName).item(0);

const version = versionElem.textContent.split('.');
tl.setVariable(`${prefix}Version.Major`, version[0]);
Expand Down

0 comments on commit b841230

Please sign in to comment.