From fd856ea5dc198f58969c92821b749947de15ece8 Mon Sep 17 00:00:00 2001 From: Inga Lovinde <52715130+inga-lovinde@users.noreply.github.com> Date: Wed, 11 Dec 2013 11:34:25 +0400 Subject: [PATCH] AssemblyInfo.cs rewriting implemented Closes #2 --- BuildServer/lib/tasks/dotnetbuild.js | 19 ++++++--- BuildServer/lib/tasks/dotnetrewrite.js | 55 ++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 5 deletions(-) create mode 100644 BuildServer/lib/tasks/dotnetrewrite.js diff --git a/BuildServer/lib/tasks/dotnetbuild.js b/BuildServer/lib/tasks/dotnetbuild.js index 2fe2d0e..6784468 100644 --- a/BuildServer/lib/tasks/dotnetbuild.js +++ b/BuildServer/lib/tasks/dotnetbuild.js @@ -1,11 +1,20 @@ "use strict"; -var dotNetBuilderWrapper = require('./dotnetbuilderwrapper'); +var sequential = require('./sequential'); module.exports = function (params, processor) { - return dotNetBuilderWrapper({ - command: "compile", - SolutionPath: processor.context.exported + "/" + params.solution//, -// OutputPath: processor.context.release + "/" + params.solution + "/" + return sequential({ + tasks: [ + { + type: "dotnetrewrite", + }, + { + type: "dotnetbuilderwrapper", + params: { + command: "compile", + SolutionPath: processor.context.exported + "/" + params.solution + } + } + ] }, processor); }; diff --git a/BuildServer/lib/tasks/dotnetrewrite.js b/BuildServer/lib/tasks/dotnetrewrite.js new file mode 100644 index 0000000..91a1b0a --- /dev/null +++ b/BuildServer/lib/tasks/dotnetrewrite.js @@ -0,0 +1,55 @@ +"use strict"; + +var fs = require('fs'); +var async = require('async'); +var glob = require('glob'); + +module.exports = function (params, processor) { + return { + process: function () { + if (processor.context.dotnetrewriterDone) { + return processor.done(); + } + + processor.context.dotnetrewriterDone = true; + + var date = new Date(), + version = date.getFullYear() + "." + + (date.getMonth() + 1) + "." + + date.getDay() + "." + + ((date.getHours() * 100 + date.getMinutes()) * 100 + date.getSeconds()) + " (" + + "built from " + processor.context.rev + "; " + + "repository: " + processor.context.owner + "/" + processor.context.reponame + "; " + + "branch: " + processor.context.branch + ")"; + + var textToAppend = "\r\n[assembly: AssemblyInformationalVersion(\"" + version + "\")]\r\n" + + glob("**/AssemblyInfo.cs", {cwd: processor.context.exported}, function (err, files) { + if (err) { + processor.onError(err); + return processor.done(); + } + + processor.onInfo("Found " + files.length + " AssemblyInfo.cs files"); + + if (!files || !files.length) { + processor.onWarn("No AssemblyInfo.cs found"); + return processor.done(); + } + + return async.parallel(files.map(function (file) { + return function (callback) { + return fs.appendFile(processor.context.exported + "/" + file, textToAppend, function (err, result) { + if (err) { + processor.onError("Unable to rewrite file " + file + ": " + err); + } else { + processor.onInfo("Rewritten file " + file); + } + callback(err, result); + }); + } + }), processor.done.bind(processor)); + }) + } + }; +};