From 3b7acb1b254f7e6c0a26ff594e82076181fa23d9 Mon Sep 17 00:00:00 2001 From: Inga Lovinde <52715130+inga-lovinde@users.noreply.github.com> Date: Fri, 3 Mar 2017 10:43:51 +0300 Subject: [PATCH] Refactored settings usage; got rid of global settings object --- BuildServer/lib/builder.ts | 27 ++++--- BuildServer/lib/commenter.ts | 9 +-- BuildServer/lib/github-wrapper.ts | 5 +- BuildServer/lib/index.ts | 76 ++++++++++--------- BuildServer/lib/report-processor.ts | 12 +-- BuildServer/lib/routes/artifact.ts | 6 +- BuildServer/lib/routes/manual.ts | 6 +- BuildServer/lib/routes/postreceive.ts | 10 +-- BuildServer/lib/routes/release.ts | 3 +- BuildServer/lib/routes/status.ts | 7 +- BuildServer/lib/settings-wrapper.ts | 12 +++ BuildServer/lib/status-processor.ts | 21 ++--- BuildServer/lib/task-processor.ts | 6 +- BuildServer/lib/tasks/dotnetbuilderwrapper.ts | 3 +- BuildServer/lib/tasks/dotnetcompile.ts | 13 ++-- BuildServer/lib/tasks/dotnetnugetpushonly.ts | 5 +- BuildServer/lib/tasks/dotnetrewrite.ts | 7 +- BuildServer/lib/tasks/eslintbrowser.ts | 7 +- BuildServer/lib/types/task-processor-types.ts | 3 + 19 files changed, 129 insertions(+), 109 deletions(-) create mode 100644 BuildServer/lib/settings-wrapper.ts diff --git a/BuildServer/lib/builder.ts b/BuildServer/lib/builder.ts index acdbbaf..7713291 100644 --- a/BuildServer/lib/builder.ts +++ b/BuildServer/lib/builder.ts @@ -6,13 +6,12 @@ import { mkdirsSync, remove } from "fs-extra"; import * as JSONParse from "json-parse-safe"; import { join } from "path"; -import settings from "../settings"; import { gitLoader } from "./git/loader"; import { createGithub } from "./github-wrapper"; import { send as sendMail } from "./mail-sender"; import { writeReport } from "./report-processor"; import { processTask } from "./task-processor"; -import { ReportResult } from "./types"; +import { ReportResult, Settings } from "./types"; const codePostfix = ""; const mailLazinessLevel = 1000; @@ -36,7 +35,7 @@ const createBuildDoneMessage = (isSuccess, name) => { return `Build failed for ${name}`; }; -const notifyStatus = (options, notifyStatusCallback) => { +const notifyStatus = (settings: Settings, options, notifyStatusCallback) => { const status = { description: String(options.description || "").substr(0, maxDescriptionLength), owner: options.owner, @@ -46,7 +45,7 @@ const notifyStatus = (options, notifyStatusCallback) => { target_url: `${settings.siteRoot}status/${options.owner}/${options.reponame}/${options.hash}`, }; - createGithub(options.owner).repos.createStatus(status, (createStatusErr) => { + createGithub(settings, options.owner).repos.createStatus(status, (createStatusErr) => { if (createStatusErr) { console.log(`Error while creating status: ${createStatusErr}`); console.log(status); @@ -66,17 +65,17 @@ const wrapGitLoader = (skipGitLoader) => { return (gitLoaderOptions, gitLoaderCallback) => process.nextTick(gitLoaderCallback); }; -export const build = (options, buildCallback) => { +export const build = (settings: Settings, options, buildCallback) => { const url = options.url; const owner = options.owner; const reponame = options.reponame; const rev = options.rev; const branch = options.branch; const skipGitLoader = options.skipGitLoader; - const local = join(options.app.get("gitpath"), "r"); - const tmp = join(options.app.get("tmpcodepath"), rev.substr(0, maxTmpcodepathLength)); + const local = join(settings.gitpath, "r"); + const tmp = join(settings.tmpcodepath, rev.substr(0, maxTmpcodepathLength)); const exported = tmp + codePostfix; - const release = join(options.app.get("releasepath"), owner, reponame, branch, rev); + const release = join(settings.releasepath, owner, reponame, branch, rev); const statusQueue = queue((task: (callback: any) => void, queueCallback) => task(queueCallback), 1); const actualGitLoader = wrapGitLoader(skipGitLoader); const date = new Date(); @@ -87,7 +86,7 @@ export const build = (options, buildCallback) => { const version = `${versionMajor}.${versionMinor}.${versionBuild}.${versionRev}`; const versionInfo = `${version}; built from ${rev}; repository: ${owner}/${reponame}; branch: ${branch}`; - statusQueue.push((queueCallback) => notifyStatus({ + statusQueue.push((queueCallback) => notifyStatus(settings, { description: "Preparing to build...", hash: rev, owner, @@ -97,9 +96,9 @@ export const build = (options, buildCallback) => { mkdirsSync(release); - writeFileSync(join(options.app.get("releasepath"), owner, reponame, branch, "latest.id"), rev); - mkdirsSync(join(options.app.get("releasepath"), owner, reponame, "$revs")); - writeFileSync(join(options.app.get("releasepath"), owner, reponame, "$revs", `${rev}.branch`), branch); + writeFileSync(join(settings.releasepath, owner, reponame, branch, "latest.id"), rev); + mkdirsSync(join(settings.releasepath, owner, reponame, "$revs")); + writeFileSync(join(settings.releasepath, owner, reponame, "$revs", `${rev}.branch`), branch); const createErrorMessageForMail = (doneErr) => { if (!doneErr) { @@ -127,7 +126,7 @@ export const build = (options, buildCallback) => { writeReport(release, doneErr, result, (writeErr) => { statusQueue.push((queueCallback) => parallel([ - (parallelCallback) => notifyStatus({ + (parallelCallback) => notifyStatus(settings, { description: errorMessage || warnMessage || infoMessage || "Success", hash: rev, owner, @@ -191,7 +190,7 @@ export const build = (options, buildCallback) => { return done("MBSMalformed"); } - return processTask(value, { + return processTask(settings, value, { branch, exported, owner, diff --git a/BuildServer/lib/commenter.ts b/BuildServer/lib/commenter.ts index f25a1fd..9acfc3b 100644 --- a/BuildServer/lib/commenter.ts +++ b/BuildServer/lib/commenter.ts @@ -2,13 +2,12 @@ import * as _ from "underscore"; -import settings from "../settings"; import { createGithub, IGithub } from "./github-wrapper"; import { getStatusMessageFromRelease } from "./report-processor"; +import { Settings } from "./types"; interface ICommentOnPullRequestOptions { readonly action: string; - readonly app: any; readonly baseRepoOptions: any; readonly headRepoOptions: any; } @@ -159,17 +158,17 @@ const checkPullRequest = (options: ICheckPullRequestOptions, callback) => { }); }; -export const commentOnPullRequest = (originalOptions: ICommentOnPullRequestOptions, callback) => { +export const commentOnPullRequest = (settings: Settings, originalOptions: ICommentOnPullRequestOptions, callback) => { const optionsGithub = { ...originalOptions, - github: createGithub(originalOptions.baseRepoOptions.owner), + github: createGithub(settings, originalOptions.baseRepoOptions.owner), }; const options = { ...optionsGithub, onTenthAttempt: () => writeComment(optionsGithub, "Waiting for build to finish...", _.noop), }; - return checkPullRequest(options, () => getStatusMessageFromRelease(options.app, options.headRepoOptions, (statusMessageErr, statusSuccessMessage) => { + return checkPullRequest(options, () => getStatusMessageFromRelease(settings, options.headRepoOptions, (statusMessageErr, statusSuccessMessage) => { const escapedErr = String(statusMessageErr || "").substring(0, maxCommentLength) .replace(/`/g, "` "); const message = statusMessageErr diff --git a/BuildServer/lib/github-wrapper.ts b/BuildServer/lib/github-wrapper.ts index 4ad949e..a42657b 100644 --- a/BuildServer/lib/github-wrapper.ts +++ b/BuildServer/lib/github-wrapper.ts @@ -1,7 +1,8 @@ "use strict"; import * as RawGithub from "github"; -import settings from "../settings"; + +import { Settings } from "./types"; interface IHttpError extends Error { readonly message: string; @@ -40,7 +41,7 @@ interface IGithub { }; } -const createGithub = (repoOwner) => settings.createGithub(repoOwner) as any as IGithub; +const createGithub = (settings: Settings, repoOwner) => settings.createGithub(repoOwner) as any as IGithub; export { IGithub, diff --git a/BuildServer/lib/index.ts b/BuildServer/lib/index.ts index 1f311f7..bc00cde 100644 --- a/BuildServer/lib/index.ts +++ b/BuildServer/lib/index.ts @@ -17,39 +17,45 @@ import * as serveStatic from "serve-static"; import settings from "../settings"; import * as routes from "./routes"; +import { setSettings } from "./settings-wrapper"; +import { Settings } from "./types"; -const app = express(); - -app.set("port", settings.port); -app.set("views", settings.viewspath); -app.set("view engine", "jade"); -app.set("gitpath", settings.gitpath); -app.set("tmpcodepath", settings.tmpcodepath); -app.set("releasepath", settings.releasepath); -app.use(serveFavicon(settings.faviconpath)); -app.use(morgan("dev")); -app.use(bodyJson({ limit: "10mb" })); -app.use(bodyUrlencoded({ extended: false })); -app.use(methodOverride()); -app.use(serveStatic(settings.staticcontentpath)); - -if (app.get("env") === "development") { - app.use(errorhandler()); -} - -app.route("/").get(routes.index); -app.route("/github/postreceive") - .post(routes.postreceive) - .get((req, res) => res.send("Only automated POST requests are allowed for postreceive route")); - -app.route("/manual") - .get(routes.manual.get) - .post(routes.manual.post); - -app.route("/status/:owner/:reponame/:branch/:rev?").get(routes.status.page); -app.route("/pos-github.payonline.ru/*").get(routes.status.pageFromGithub); -app.route("/status.svg").get(routes.status.image); -app.route("/release/:owner/:reponame/:branch/:rev").get(routes.release); -app.route("/artifact/:owner/:reponame/:branch/:rev/*").get(routes.artifact); - -createServer(app).listen(app.get("port"), () => console.log(`Express server listening on port ${app.get("port")}`)); +const run = (settings: Settings) => { + + const app = express(); + + app.set("port", settings.port); + app.set("views", settings.viewspath); + app.set("view engine", "jade"); + setSettings(app, settings); + + app.use(serveFavicon(settings.faviconpath)); + app.use(morgan("dev")); + app.use(bodyJson({ limit: "10mb" })); + app.use(bodyUrlencoded({ extended: false })); + app.use(methodOverride()); + app.use(serveStatic(settings.staticcontentpath)); + + if (app.get("env") === "development") { + app.use(errorhandler()); + } + + app.route("/").get(routes.index); + app.route("/github/postreceive") + .post(routes.postreceive) + .get((req, res) => res.send("Only automated POST requests are allowed for postreceive route")); + + app.route("/manual") + .get(routes.manual.get) + .post(routes.manual.post); + + app.route("/status/:owner/:reponame/:branch/:rev?").get(routes.status.page); + app.route("/pos-github.payonline.ru/*").get(routes.status.pageFromGithub); + app.route("/status.svg").get(routes.status.image); + app.route("/release/:owner/:reponame/:branch/:rev").get(routes.release); + app.route("/artifact/:owner/:reponame/:branch/:rev/*").get(routes.artifact); + + createServer(app).listen(app.get("port"), () => console.log(`Express server listening on port ${app.get("port")}`)); +}; + +export default run; diff --git a/BuildServer/lib/report-processor.ts b/BuildServer/lib/report-processor.ts index bf7df51..ab22406 100644 --- a/BuildServer/lib/report-processor.ts +++ b/BuildServer/lib/report-processor.ts @@ -8,7 +8,7 @@ import { ReadableStreamBuffer, WritableStreamBuffer } from "stream-buffers"; import * as _ from "underscore"; import { createGunzip, createGzip } from "zlib"; -import { Message, Report, ReportResult } from "./types"; +import { Message, Report, ReportResult, Settings } from "./types"; const reportFilename = "report.json.gz"; const maxAttemptsNumber = 100; @@ -78,8 +78,8 @@ export const readReport = (releaseDir, callback) => { }); }; -export const loadReport = (app, options, callback) => { - const releaseDir = join(app.get("releasepath"), options.owner, options.reponame, options.branch, options.rev); +export const loadReport = (settings: Settings, options, callback) => { + const releaseDir = join(settings.releasepath, options.owner, options.reponame, options.branch, options.rev); glob("**", { cwd: releaseDir, @@ -114,12 +114,12 @@ export const loadReport = (app, options, callback) => { }); }; -export const getStatusMessageFromRelease = (app, originalOptions, callback) => { +export const getStatusMessageFromRelease = (settings: Settings, originalOptions, callback) => { const options = { ...originalOptions, attemptsGetReport: (Number(originalOptions.attemptsGetReport) || Number()) + 1, }; - const releaseDir = join(app.get("releasepath"), options.owner, options.reponame, options.branch, options.rev); + const releaseDir = join(settings.releasepath, options.owner, options.reponame, options.branch, options.rev); const reportFile = join(releaseDir, reportFilename); exists(reportFile, (reportFileExists) => { @@ -138,7 +138,7 @@ export const getStatusMessageFromRelease = (app, originalOptions, callback) => { options.onTenthAttempt(); } - return setTimeout(() => exports.getStatusMessageFromRelease(app, options, callback), attemptsTimeout); + return setTimeout(() => exports.getStatusMessageFromRelease(settings, options, callback), attemptsTimeout); }), directoryCheckTimeout); } diff --git a/BuildServer/lib/routes/artifact.ts b/BuildServer/lib/routes/artifact.ts index b1546fb..57b3f60 100644 --- a/BuildServer/lib/routes/artifact.ts +++ b/BuildServer/lib/routes/artifact.ts @@ -1,5 +1,7 @@ "use strict"; +import { getSettings } from "../settings-wrapper"; + export default (req, res) => { const options = { branch: `/refs/heads/${req.params.branch}`, @@ -10,7 +12,9 @@ export default (req, res) => { rev: req.params.rev, }; - const pathParts = [req.app.get("releasepath"), options.owner, options.reponame, options.branch, options.rev, options.file]; + const settings = getSettings(req.app); + + const pathParts = [settings.releasepath, options.owner, options.reponame, options.branch, options.rev, options.file]; res.sendfile(pathParts.join("/")); }; diff --git a/BuildServer/lib/routes/manual.ts b/BuildServer/lib/routes/manual.ts index 1cc0ffd..baebd88 100644 --- a/BuildServer/lib/routes/manual.ts +++ b/BuildServer/lib/routes/manual.ts @@ -2,17 +2,19 @@ import * as _ from "underscore"; import { build } from "../builder"; +import { getSettings } from "../settings-wrapper"; export const get = (req, res) => res.render("manual"); export const post = (req, res) => { + const settings = getSettings(req.app); + const options = { ...req.body, - app: req.app, url: `https://pos-github.payonline.ru/${req.body.owner}/${req.body.reponame}`, }; - build(options, (err, result) => { + build(settings, options, (err, result) => { console.log("Done processing manual request"); console.log(`Error: ${err}`); res.render("manual-done", { diff --git a/BuildServer/lib/routes/postreceive.ts b/BuildServer/lib/routes/postreceive.ts index c4b7d33..73deefe 100644 --- a/BuildServer/lib/routes/postreceive.ts +++ b/BuildServer/lib/routes/postreceive.ts @@ -3,13 +3,14 @@ import * as JSONParse from "json-parse-safe"; import { build } from "../builder"; import { commentOnPullRequest } from "../commenter"; +import { getSettings } from "../settings-wrapper"; const getBranchDescription = (options) => `${options.owner}/${options.reponame}:${options.branchname || options.branch}`; const processPush = (req, res, payload) => { + const settings = getSettings(req.app); const repository = payload.repository; const options = { - app: req.app, branch: payload.ref, owner: repository.owner.name, reponame: repository.name, @@ -19,7 +20,7 @@ const processPush = (req, res, payload) => { console.log(`Got push event for ${getBranchDescription(options)}`); - build(options, (err, result) => { + build(settings, options, (err, result) => { console.log("Done processing request from GitHub"); console.log(`Error: ${err}`); res.send(`Done processing request from GitHub\r\nError: ${err}\r\nResult: ${result}`); @@ -47,16 +48,15 @@ const processPullRequest = (req, res, payload) => { owner: baseRepo.owner.name || baseRepo.owner.login, reponame: baseRepo.name, }; + const settings = getSettings(req.app); const options = { action, - app: req.app, baseRepoOptions, headRepoOptions, pullRequestNumber, }; const masterOptions = { action, - app: req.app, baseRepoOptions, headRepoOptions: baseRepoOptions, pullRequestNumber, @@ -79,7 +79,7 @@ const processPullRequest = (req, res, payload) => { return res.send(""); } - return commentOnPullRequest((action === "closed" && masterOptions) || options, (err, data) => { + return commentOnPullRequest(settings, (action === "closed" && masterOptions) || options, (err, data) => { if (err) { console.log(`Unable to post comment: ${err}`); } diff --git a/BuildServer/lib/routes/release.ts b/BuildServer/lib/routes/release.ts index ca0fe7d..e46f512 100644 --- a/BuildServer/lib/routes/release.ts +++ b/BuildServer/lib/routes/release.ts @@ -4,6 +4,7 @@ import { create as createArchiver } from "archiver"; import { join } from "path"; import { readReport } from "../report-processor"; +import { getSettings } from "../settings-wrapper"; const getDatePart = (report) => { if (!report.date) { @@ -32,7 +33,7 @@ export default (req, res, next) => { rev: req.params.rev, }; - const releasePath = join(req.app.get("releasepath"), options.owner, options.reponame, options.branch, options.rev); + const releasePath = join(getSettings(req.app).releasepath, options.owner, options.reponame, options.branch, options.rev); readReport(releasePath, (err, report) => { if (err) { diff --git a/BuildServer/lib/routes/status.ts b/BuildServer/lib/routes/status.ts index 7886484..7140fdc 100644 --- a/BuildServer/lib/routes/status.ts +++ b/BuildServer/lib/routes/status.ts @@ -3,6 +3,7 @@ import * as _ from "underscore"; import { parse } from "url"; +import { getSettings } from "../settings-wrapper"; import { getReport } from "../status-processor"; const parseOptionsFromReferer = (path, callback) => { @@ -101,7 +102,7 @@ export const image = (req, res) => { return handle(err, options); } - return getReport(req.app, options, handle); + return getReport(getSettings(req.app), options, handle); }); }; @@ -114,7 +115,7 @@ export const page = (req, res) => { rev: req.params.rev, }; - getReport(req.app, options, createShowReport(res)); + getReport(getSettings(req.app), options, createShowReport(res)); }; export const pageFromGithub = (req, res) => parseOptionsFromReferer(req.params[0], (err, options) => { @@ -122,5 +123,5 @@ export const pageFromGithub = (req, res) => parseOptionsFromReferer(req.params[0 return createShowReport(res)(err, options); } - return getReport(req.app, options, createShowReport(res)); + return getReport(req.app /* xxx */, options, createShowReport(res)); }); diff --git a/BuildServer/lib/settings-wrapper.ts b/BuildServer/lib/settings-wrapper.ts new file mode 100644 index 0000000..399a919 --- /dev/null +++ b/BuildServer/lib/settings-wrapper.ts @@ -0,0 +1,12 @@ +"use strict"; + +import { Settings } from "./types"; + +const getSettings = (app): Settings => app.get("mbsSettings"); + +const setSettings = (app, settings: Settings) => app.set("mbsSettings", settings); + +export { + getSettings, + setSettings, +}; diff --git a/BuildServer/lib/status-processor.ts b/BuildServer/lib/status-processor.ts index 63c385e..b490c3d 100644 --- a/BuildServer/lib/status-processor.ts +++ b/BuildServer/lib/status-processor.ts @@ -5,9 +5,10 @@ import { join } from "path"; import * as _ from "underscore"; import { loadReport } from "./report-processor"; +import { Settings } from "./types"; -const addBranchInfo = (app, options, callback) => { - const branchFile = join(app.get("releasepath"), options.owner, options.reponame, "$revs", `${options.rev}.branch`); +const addBranchInfo = (settings: Settings, options, callback) => { + const branchFile = join(settings.releasepath, options.owner, options.reponame, "$revs", `${options.rev}.branch`); exists(branchFile, (exists) => { if (!exists) { @@ -32,8 +33,8 @@ const addBranchInfo = (app, options, callback) => { }); }; -const addRevInfo = (app, options, callback) => { - const revFile = join(app.get("releasepath"), options.owner, options.reponame, options.branch, "latest.id"); +const addRevInfo = (settings: Settings, options, callback) => { + const revFile = join(settings.releasepath, options.owner, options.reponame, options.branch, "latest.id"); exists(revFile, (exists) => { if (!exists) { @@ -55,7 +56,7 @@ const addRevInfo = (app, options, callback) => { }); }; -const parseOptions = (app, options, callback) => { +const parseOptions = (settings: Settings, options, callback) => { if (options.rev && !(/^[\da-f]{40}$/i).test(options.rev)) { return callback(`Wrong rev format: ${options.rev}`, options); } @@ -66,14 +67,14 @@ const parseOptions = (app, options, callback) => { }; if (options.rev) { - return addBranchInfo(app, { + return addBranchInfo(settings, { ...result, rev: options.rev, }, callback); } if (/^[\da-f]{40}$/i.test(options.branchName)) { - return addBranchInfo(app, { + return addBranchInfo(settings, { ...result, rev: options.branchName, }, callback); @@ -81,17 +82,17 @@ const parseOptions = (app, options, callback) => { const branchName = options.branchName || "master"; - return addRevInfo(app, { + return addRevInfo(settings, { ...result, branch: `refs/heads/${branchName}`, branchName, }, callback); }; -export const getReport = (app, options, callback) => parseOptions(app, options, (err, result) => { +export const getReport = (settings: Settings, options, callback) => parseOptions(settings, options, (err, result) => { if (err) { return callback(err, {}); } - return loadReport(app, result, callback); + return loadReport(settings, result, callback); }); diff --git a/BuildServer/lib/task-processor.ts b/BuildServer/lib/task-processor.ts index 9e35844..e874300 100644 --- a/BuildServer/lib/task-processor.ts +++ b/BuildServer/lib/task-processor.ts @@ -3,7 +3,7 @@ import * as _ from "underscore"; import tasks from "./tasks"; -import { MessagesRoot, TaskInfo, TaskProcessor, TaskProcessorCallback, TaskProcessorCore } from "./types"; +import { MessagesRoot, Settings, TaskInfo, TaskProcessor, TaskProcessorCallback, TaskProcessorCore } from "./types"; // TaskProcessor does not look like EventEmitter, so no need to extend EventEmitter and use `emit' here. const createTaskProcessor = (task: TaskInfo, outerProcessor: TaskProcessorCore, callback: TaskProcessorCallback) => { @@ -31,6 +31,7 @@ const createTaskProcessor = (task: TaskInfo, outerProcessor: TaskProcessorCore, onInfo, process: () => tasks[task.type](task.params || {}, result)(), processTask: (innerTask, innerCallback) => createTaskProcessor(innerTask, result, innerCallback).process(), + settings: outerProcessor.settings, }; return result; @@ -65,7 +66,7 @@ const addFlag = (flags) => (flagName) => { const containsFlag = (flags) => (flagName) => flags[flagName]; -export const processTask = (task, context, callback) => { +export const processTask = (settings: Settings, task, context, callback) => { const errors: MessagesRoot = { $allMessages: [] }; const warns: MessagesRoot = { $allMessages: [] }; const infos: MessagesRoot = { $allMessages: [] }; @@ -86,6 +87,7 @@ export const processTask = (task, context, callback) => { onError: messageProcessor(errors), onInfo: messageProcessor(infos), onWarn: messageProcessor(warns), + settings, }, (err) => callback(err, { errors, infos, diff --git a/BuildServer/lib/tasks/dotnetbuilderwrapper.ts b/BuildServer/lib/tasks/dotnetbuilderwrapper.ts index 1b3c4da..77f9cc9 100644 --- a/BuildServer/lib/tasks/dotnetbuilderwrapper.ts +++ b/BuildServer/lib/tasks/dotnetbuilderwrapper.ts @@ -4,7 +4,6 @@ import { spawn } from "child_process"; import * as JSONParse from "json-parse-safe"; import { WritableStreamBuffer } from "stream-buffers"; -import settings from "../../settings"; import { Task } from "../types"; const wrapBuilder = (builder, input, onExit) => { @@ -46,7 +45,7 @@ const wrapBuilder = (builder, input, onExit) => { export default ((params, processor) => () => { const input = JSON.stringify(params); - const builder = spawn(settings.builderExecutable, [params.command]); + const builder = spawn(processor.settings.builderExecutable, [params.command]); processor.onInfo(`DotNetBuilderWrapper processing (at ${new Date().toISOString()}): ${input}`); diff --git a/BuildServer/lib/tasks/dotnetcompile.ts b/BuildServer/lib/tasks/dotnetcompile.ts index 4cba0ed..faac647 100644 --- a/BuildServer/lib/tasks/dotnetcompile.ts +++ b/BuildServer/lib/tasks/dotnetcompile.ts @@ -3,30 +3,27 @@ import { join } from "path"; import * as _ from "underscore"; -import rawSettings from "../../settings"; import { Settings, Task } from "../types"; import dotnetbuilderwrapper from "./dotnetbuilderwrapper"; -const settings: Settings = rawSettings; - export default ((params, processor) => { - if (settings.isCodeAnalysisUnsupported && params.forceCodeAnalysis) { + if (processor.settings.isCodeAnalysisUnsupported && params.forceCodeAnalysis) { processor.onError("Code analysis is not supported"); return processor.done(); } const getAdditionalSigningParameters = () => { - if (settings.skipCodeSigning || params.skipCodeSigning) { + if (processor.settings.skipCodeSigning || params.skipCodeSigning) { return {}; } - return { SigningKey: settings.codeSigningKeyFile }; + return { SigningKey: processor.settings.codeSigningKeyFile }; }; - const skipCodeAnalysis = settings.isCodeAnalysisUnsupported + const skipCodeAnalysis = processor.settings.isCodeAnalysisUnsupported || params.ignoreCodeAnalysis - || (settings.ignoreCodeAnalysisByDefault && !params.forceCodeAnalysis); + || (processor.settings.ignoreCodeAnalysisByDefault && !params.forceCodeAnalysis); const compileParams = { Configuration: params.configuration, diff --git a/BuildServer/lib/tasks/dotnetnugetpushonly.ts b/BuildServer/lib/tasks/dotnetnugetpushonly.ts index 11dd0b9..ff214fa 100644 --- a/BuildServer/lib/tasks/dotnetnugetpushonly.ts +++ b/BuildServer/lib/tasks/dotnetnugetpushonly.ts @@ -2,13 +2,12 @@ import { join } from "path"; -import settings from "../../settings"; import { Task } from "../types"; import dotnetbuilderwrapper from "./dotnetbuilderwrapper"; export default ((params, processor) => dotnetbuilderwrapper({ - ApiKey: settings.nugetApiKey, - NugetHost: settings.nugetHost, + ApiKey: processor.settings.nugetApiKey, + NugetHost: processor.settings.nugetHost, Package: join(processor.context.exported, params.Package), command: "nugetpush", }, processor)) as Task; diff --git a/BuildServer/lib/tasks/dotnetrewrite.ts b/BuildServer/lib/tasks/dotnetrewrite.ts index 11a49fb..3380652 100644 --- a/BuildServer/lib/tasks/dotnetrewrite.ts +++ b/BuildServer/lib/tasks/dotnetrewrite.ts @@ -5,21 +5,18 @@ import { readFile, writeFile } from "fs"; import * as glob from "glob"; import { join } from "path"; -import rawSettings from "../../settings"; import { Settings, Task } from "../types"; const flagDoneName = "dotnetrewriterDone"; -const settings: Settings = rawSettings; - const processAssemblyInfo = (params, processor, appendInformationalVersion) => (originalContent, cb) => { const processInternalsVisible = (content) => { - if (params.skipCodeSigning || settings.skipCodeSigning) { + if (params.skipCodeSigning || processor.settings.xxxskipCodeSigning) { return content; } const pattern = /InternalsVisibleTo\s*\(\s*"([\w.]+)"\s*\)/g; - const replacer = (match, p1) => `InternalsVisibleTo("${p1},PublicKey=${settings.codeSigningPublicKey}")`; + const replacer = (match, p1) => `InternalsVisibleTo("${p1},PublicKey=${processor.settings.codeSigningPublicKey}")`; return content.replace(pattern, replacer); }; diff --git a/BuildServer/lib/tasks/eslintbrowser.ts b/BuildServer/lib/tasks/eslintbrowser.ts index 575b19a..56612af 100644 --- a/BuildServer/lib/tasks/eslintbrowser.ts +++ b/BuildServer/lib/tasks/eslintbrowser.ts @@ -3,19 +3,16 @@ import { CLIEngine } from "eslint"; import { join } from "path"; -import rawSettings from "../../settings"; import { Settings, Task } from "../types"; -const settings: Settings = rawSettings; - const errorSeverity = 2; export default ((params, processor) => () => { - if (settings.isCodeAnalysisUnsupported) { + if (processor.settings.isCodeAnalysisUnsupported) { return; } - const cli = new CLIEngine({ configFile: settings.eslintBrowserConfig }); + const cli = new CLIEngine({ configFile: processor.settings.eslintBrowserConfig }); const filePath = join(processor.context.exported, params.filename); const result = cli.executeOnFiles([filePath]); diff --git a/BuildServer/lib/types/task-processor-types.ts b/BuildServer/lib/types/task-processor-types.ts index 68bfa93..68f744b 100644 --- a/BuildServer/lib/types/task-processor-types.ts +++ b/BuildServer/lib/types/task-processor-types.ts @@ -1,9 +1,12 @@ +import { Settings } from "./settings-types"; + export type TaskProcessorCallback = (err: string) => void; export interface ITaskProcessorCore { readonly onError: (message: string | Error, prefix?: string) => void; readonly onWarn: (message: string, prefix?: string) => void; readonly onInfo: (message: string, prefix?: string) => void; + readonly settings: Settings; readonly context?: any; }