Build server prototype (integration with GitHub / NuGet / etc)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
micro-build-server/BuildServer/lib/tasks/dotnetrewrite.js

70 lines
2.2 KiB

"use strict";
const fs = require('fs');
const async = require('async');
const glob = require('glob');
const settings = require('../../settings');
const addAssemblyAttribute = (content, attribute) => content + "\n" + attribute + "\n";
module.exports = (params, processor) => ({
process: () => {
if (processor.context.dotnetrewriterDone) {
return processor.done();
}
processor.context.dotnetrewriterDone = true;
const date = new Date();
const version = date.getFullYear() + "." +
(date.getMonth() + 1) + "." +
date.getDate() + "." +
(date.getHours() * 100 + date.getMinutes()) + "; " +
"built from " + processor.context.rev + "; " +
"repository: " + processor.context.owner + "/" + processor.context.reponame + "; " +
"branch: " + processor.context.branch;
const processAssemblyInfo = (appendInformationalVersion) => (content, cb) => {
if (!params.skipCodeSigning && !settings.skipCodeSigning) {
content = content.replace(
/InternalsVisibleTo\s*\(\s*"([\w.]+)"\s*\)/g,
(match, p1) => "InternalsVisibleTo(\"" + p1 + ",PublicKey=" + settings.codeSigningPublicKey + "\")"
);
}
if (appendInformationalVersion) {
content = addAssemblyAttribute(content, "[assembly: System.Reflection.AssemblyInformationalVersion(\"" + version + "\")]");
}
return cb(null, content);
};
glob("**/{InternalsVisible,AssemblyInfo}*.cs", {cwd: processor.context.exported}, (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((file) => (callback) => async.waterfall([
fs.readFile.bind(null, processor.context.exported + "/" + file, { encoding: "utf8" }),
processAssemblyInfo(file.toLowerCase().indexOf("assemblyinfo.cs") >= 0),
fs.writeFile.bind(null, processor.context.exported + "/" + file)
], (err) => {
if (err) {
processor.onError("Unable to rewrite file " + file + ": " + err);
} else {
processor.onInfo("Rewritten file " + file);
}
callback(err);
})), processor.done.bind(processor));
});
}
});