Refactored settings usage; got rid of global settings object

dependabot/npm_and_yarn/BuildServer/eslint-7.2.0
Inga 🏳‍🌈 8 years ago
parent e05cd07b89
commit 3b7acb1b25
  1. 27
      BuildServer/lib/builder.ts
  2. 9
      BuildServer/lib/commenter.ts
  3. 5
      BuildServer/lib/github-wrapper.ts
  4. 76
      BuildServer/lib/index.ts
  5. 12
      BuildServer/lib/report-processor.ts
  6. 6
      BuildServer/lib/routes/artifact.ts
  7. 6
      BuildServer/lib/routes/manual.ts
  8. 10
      BuildServer/lib/routes/postreceive.ts
  9. 3
      BuildServer/lib/routes/release.ts
  10. 7
      BuildServer/lib/routes/status.ts
  11. 12
      BuildServer/lib/settings-wrapper.ts
  12. 21
      BuildServer/lib/status-processor.ts
  13. 6
      BuildServer/lib/task-processor.ts
  14. 3
      BuildServer/lib/tasks/dotnetbuilderwrapper.ts
  15. 13
      BuildServer/lib/tasks/dotnetcompile.ts
  16. 5
      BuildServer/lib/tasks/dotnetnugetpushonly.ts
  17. 7
      BuildServer/lib/tasks/dotnetrewrite.ts
  18. 7
      BuildServer/lib/tasks/eslintbrowser.ts
  19. 3
      BuildServer/lib/types/task-processor-types.ts

@ -6,13 +6,12 @@ import { mkdirsSync, remove } from "fs-extra";
import * as JSONParse from "json-parse-safe"; import * as JSONParse from "json-parse-safe";
import { join } from "path"; import { join } from "path";
import settings from "../settings";
import { gitLoader } from "./git/loader"; import { gitLoader } from "./git/loader";
import { createGithub } from "./github-wrapper"; import { createGithub } from "./github-wrapper";
import { send as sendMail } from "./mail-sender"; import { send as sendMail } from "./mail-sender";
import { writeReport } from "./report-processor"; import { writeReport } from "./report-processor";
import { processTask } from "./task-processor"; import { processTask } from "./task-processor";
import { ReportResult } from "./types"; import { ReportResult, Settings } from "./types";
const codePostfix = ""; const codePostfix = "";
const mailLazinessLevel = 1000; const mailLazinessLevel = 1000;
@ -36,7 +35,7 @@ const createBuildDoneMessage = (isSuccess, name) => {
return `Build failed for ${name}`; return `Build failed for ${name}`;
}; };
const notifyStatus = (options, notifyStatusCallback) => { const notifyStatus = (settings: Settings, options, notifyStatusCallback) => {
const status = { const status = {
description: String(options.description || "").substr(0, maxDescriptionLength), description: String(options.description || "").substr(0, maxDescriptionLength),
owner: options.owner, owner: options.owner,
@ -46,7 +45,7 @@ const notifyStatus = (options, notifyStatusCallback) => {
target_url: `${settings.siteRoot}status/${options.owner}/${options.reponame}/${options.hash}`, 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) { if (createStatusErr) {
console.log(`Error while creating status: ${createStatusErr}`); console.log(`Error while creating status: ${createStatusErr}`);
console.log(status); console.log(status);
@ -66,17 +65,17 @@ const wrapGitLoader = (skipGitLoader) => {
return (gitLoaderOptions, gitLoaderCallback) => process.nextTick(gitLoaderCallback); return (gitLoaderOptions, gitLoaderCallback) => process.nextTick(gitLoaderCallback);
}; };
export const build = (options, buildCallback) => { export const build = (settings: Settings, options, buildCallback) => {
const url = options.url; const url = options.url;
const owner = options.owner; const owner = options.owner;
const reponame = options.reponame; const reponame = options.reponame;
const rev = options.rev; const rev = options.rev;
const branch = options.branch; const branch = options.branch;
const skipGitLoader = options.skipGitLoader; const skipGitLoader = options.skipGitLoader;
const local = join(options.app.get("gitpath"), "r"); const local = join(settings.gitpath, "r");
const tmp = join(options.app.get("tmpcodepath"), rev.substr(0, maxTmpcodepathLength)); const tmp = join(settings.tmpcodepath, rev.substr(0, maxTmpcodepathLength));
const exported = tmp + codePostfix; 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 statusQueue = queue((task: (callback: any) => void, queueCallback) => task(queueCallback), 1);
const actualGitLoader = wrapGitLoader(skipGitLoader); const actualGitLoader = wrapGitLoader(skipGitLoader);
const date = new Date(); const date = new Date();
@ -87,7 +86,7 @@ export const build = (options, buildCallback) => {
const version = `${versionMajor}.${versionMinor}.${versionBuild}.${versionRev}`; const version = `${versionMajor}.${versionMinor}.${versionBuild}.${versionRev}`;
const versionInfo = `${version}; built from ${rev}; repository: ${owner}/${reponame}; branch: ${branch}`; const versionInfo = `${version}; built from ${rev}; repository: ${owner}/${reponame}; branch: ${branch}`;
statusQueue.push((queueCallback) => notifyStatus({ statusQueue.push((queueCallback) => notifyStatus(settings, {
description: "Preparing to build...", description: "Preparing to build...",
hash: rev, hash: rev,
owner, owner,
@ -97,9 +96,9 @@ export const build = (options, buildCallback) => {
mkdirsSync(release); mkdirsSync(release);
writeFileSync(join(options.app.get("releasepath"), owner, reponame, branch, "latest.id"), rev); writeFileSync(join(settings.releasepath, owner, reponame, branch, "latest.id"), rev);
mkdirsSync(join(options.app.get("releasepath"), owner, reponame, "$revs")); mkdirsSync(join(settings.releasepath, owner, reponame, "$revs"));
writeFileSync(join(options.app.get("releasepath"), owner, reponame, "$revs", `${rev}.branch`), branch); writeFileSync(join(settings.releasepath, owner, reponame, "$revs", `${rev}.branch`), branch);
const createErrorMessageForMail = (doneErr) => { const createErrorMessageForMail = (doneErr) => {
if (!doneErr) { if (!doneErr) {
@ -127,7 +126,7 @@ export const build = (options, buildCallback) => {
writeReport(release, doneErr, result, (writeErr) => { writeReport(release, doneErr, result, (writeErr) => {
statusQueue.push((queueCallback) => parallel([ statusQueue.push((queueCallback) => parallel([
(parallelCallback) => notifyStatus({ (parallelCallback) => notifyStatus(settings, {
description: errorMessage || warnMessage || infoMessage || "Success", description: errorMessage || warnMessage || infoMessage || "Success",
hash: rev, hash: rev,
owner, owner,
@ -191,7 +190,7 @@ export const build = (options, buildCallback) => {
return done("MBSMalformed"); return done("MBSMalformed");
} }
return processTask(value, { return processTask(settings, value, {
branch, branch,
exported, exported,
owner, owner,

@ -2,13 +2,12 @@
import * as _ from "underscore"; import * as _ from "underscore";
import settings from "../settings";
import { createGithub, IGithub } from "./github-wrapper"; import { createGithub, IGithub } from "./github-wrapper";
import { getStatusMessageFromRelease } from "./report-processor"; import { getStatusMessageFromRelease } from "./report-processor";
import { Settings } from "./types";
interface ICommentOnPullRequestOptions { interface ICommentOnPullRequestOptions {
readonly action: string; readonly action: string;
readonly app: any;
readonly baseRepoOptions: any; readonly baseRepoOptions: any;
readonly headRepoOptions: 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 = { const optionsGithub = {
...originalOptions, ...originalOptions,
github: createGithub(originalOptions.baseRepoOptions.owner), github: createGithub(settings, originalOptions.baseRepoOptions.owner),
}; };
const options = { const options = {
...optionsGithub, ...optionsGithub,
onTenthAttempt: () => writeComment(optionsGithub, "Waiting for build to finish...", _.noop), 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) const escapedErr = String(statusMessageErr || "").substring(0, maxCommentLength)
.replace(/`/g, "` "); .replace(/`/g, "` ");
const message = statusMessageErr const message = statusMessageErr

@ -1,7 +1,8 @@
"use strict"; "use strict";
import * as RawGithub from "github"; import * as RawGithub from "github";
import settings from "../settings";
import { Settings } from "./types";
interface IHttpError extends Error { interface IHttpError extends Error {
readonly message: string; 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 { export {
IGithub, IGithub,

@ -17,39 +17,45 @@ import * as serveStatic from "serve-static";
import settings from "../settings"; import settings from "../settings";
import * as routes from "./routes"; import * as routes from "./routes";
import { setSettings } from "./settings-wrapper";
import { Settings } from "./types";
const app = express(); const run = (settings: Settings) => {
app.set("port", settings.port); const app = express();
app.set("views", settings.viewspath);
app.set("view engine", "jade"); app.set("port", settings.port);
app.set("gitpath", settings.gitpath); app.set("views", settings.viewspath);
app.set("tmpcodepath", settings.tmpcodepath); app.set("view engine", "jade");
app.set("releasepath", settings.releasepath); setSettings(app, settings);
app.use(serveFavicon(settings.faviconpath));
app.use(morgan("dev")); app.use(serveFavicon(settings.faviconpath));
app.use(bodyJson({ limit: "10mb" })); app.use(morgan("dev"));
app.use(bodyUrlencoded({ extended: false })); app.use(bodyJson({ limit: "10mb" }));
app.use(methodOverride()); app.use(bodyUrlencoded({ extended: false }));
app.use(serveStatic(settings.staticcontentpath)); app.use(methodOverride());
app.use(serveStatic(settings.staticcontentpath));
if (app.get("env") === "development") {
app.use(errorhandler()); if (app.get("env") === "development") {
} app.use(errorhandler());
}
app.route("/").get(routes.index);
app.route("/github/postreceive") app.route("/").get(routes.index);
.post(routes.postreceive) app.route("/github/postreceive")
.get((req, res) => res.send("Only automated POST requests are allowed for postreceive route")); .post(routes.postreceive)
.get((req, res) => res.send("Only automated POST requests are allowed for postreceive route"));
app.route("/manual")
.get(routes.manual.get) app.route("/manual")
.post(routes.manual.post); .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/:owner/:reponame/:branch/:rev?").get(routes.status.page);
app.route("/status.svg").get(routes.status.image); app.route("/pos-github.payonline.ru/*").get(routes.status.pageFromGithub);
app.route("/release/:owner/:reponame/:branch/:rev").get(routes.release); app.route("/status.svg").get(routes.status.image);
app.route("/artifact/:owner/:reponame/:branch/:rev/*").get(routes.artifact); 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")}`));
createServer(app).listen(app.get("port"), () => console.log(`Express server listening on port ${app.get("port")}`));
};
export default run;

@ -8,7 +8,7 @@ import { ReadableStreamBuffer, WritableStreamBuffer } from "stream-buffers";
import * as _ from "underscore"; import * as _ from "underscore";
import { createGunzip, createGzip } from "zlib"; import { createGunzip, createGzip } from "zlib";
import { Message, Report, ReportResult } from "./types"; import { Message, Report, ReportResult, Settings } from "./types";
const reportFilename = "report.json.gz"; const reportFilename = "report.json.gz";
const maxAttemptsNumber = 100; const maxAttemptsNumber = 100;
@ -78,8 +78,8 @@ export const readReport = (releaseDir, callback) => {
}); });
}; };
export const loadReport = (app, options, callback) => { export const loadReport = (settings: Settings, options, callback) => {
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);
glob("**", { glob("**", {
cwd: releaseDir, 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 = { const options = {
...originalOptions, ...originalOptions,
attemptsGetReport: (Number(originalOptions.attemptsGetReport) || Number()) + 1, 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); const reportFile = join(releaseDir, reportFilename);
exists(reportFile, (reportFileExists) => { exists(reportFile, (reportFileExists) => {
@ -138,7 +138,7 @@ export const getStatusMessageFromRelease = (app, originalOptions, callback) => {
options.onTenthAttempt(); options.onTenthAttempt();
} }
return setTimeout(() => exports.getStatusMessageFromRelease(app, options, callback), attemptsTimeout); return setTimeout(() => exports.getStatusMessageFromRelease(settings, options, callback), attemptsTimeout);
}), directoryCheckTimeout); }), directoryCheckTimeout);
} }

@ -1,5 +1,7 @@
"use strict"; "use strict";
import { getSettings } from "../settings-wrapper";
export default (req, res) => { export default (req, res) => {
const options = { const options = {
branch: `/refs/heads/${req.params.branch}`, branch: `/refs/heads/${req.params.branch}`,
@ -10,7 +12,9 @@ export default (req, res) => {
rev: req.params.rev, 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("/")); res.sendfile(pathParts.join("/"));
}; };

@ -2,17 +2,19 @@
import * as _ from "underscore"; import * as _ from "underscore";
import { build } from "../builder"; import { build } from "../builder";
import { getSettings } from "../settings-wrapper";
export const get = (req, res) => res.render("manual"); export const get = (req, res) => res.render("manual");
export const post = (req, res) => { export const post = (req, res) => {
const settings = getSettings(req.app);
const options = { const options = {
...req.body, ...req.body,
app: req.app,
url: `https://pos-github.payonline.ru/${req.body.owner}/${req.body.reponame}`, 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("Done processing manual request");
console.log(`Error: ${err}`); console.log(`Error: ${err}`);
res.render("manual-done", { res.render("manual-done", {

@ -3,13 +3,14 @@
import * as JSONParse from "json-parse-safe"; import * as JSONParse from "json-parse-safe";
import { build } from "../builder"; import { build } from "../builder";
import { commentOnPullRequest } from "../commenter"; import { commentOnPullRequest } from "../commenter";
import { getSettings } from "../settings-wrapper";
const getBranchDescription = (options) => `${options.owner}/${options.reponame}:${options.branchname || options.branch}`; const getBranchDescription = (options) => `${options.owner}/${options.reponame}:${options.branchname || options.branch}`;
const processPush = (req, res, payload) => { const processPush = (req, res, payload) => {
const settings = getSettings(req.app);
const repository = payload.repository; const repository = payload.repository;
const options = { const options = {
app: req.app,
branch: payload.ref, branch: payload.ref,
owner: repository.owner.name, owner: repository.owner.name,
reponame: repository.name, reponame: repository.name,
@ -19,7 +20,7 @@ const processPush = (req, res, payload) => {
console.log(`Got push event for ${getBranchDescription(options)}`); 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("Done processing request from GitHub");
console.log(`Error: ${err}`); console.log(`Error: ${err}`);
res.send(`Done processing request from GitHub\r\nError: ${err}\r\nResult: ${result}`); 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, owner: baseRepo.owner.name || baseRepo.owner.login,
reponame: baseRepo.name, reponame: baseRepo.name,
}; };
const settings = getSettings(req.app);
const options = { const options = {
action, action,
app: req.app,
baseRepoOptions, baseRepoOptions,
headRepoOptions, headRepoOptions,
pullRequestNumber, pullRequestNumber,
}; };
const masterOptions = { const masterOptions = {
action, action,
app: req.app,
baseRepoOptions, baseRepoOptions,
headRepoOptions: baseRepoOptions, headRepoOptions: baseRepoOptions,
pullRequestNumber, pullRequestNumber,
@ -79,7 +79,7 @@ const processPullRequest = (req, res, payload) => {
return res.send(""); return res.send("");
} }
return commentOnPullRequest((action === "closed" && masterOptions) || options, (err, data) => { return commentOnPullRequest(settings, (action === "closed" && masterOptions) || options, (err, data) => {
if (err) { if (err) {
console.log(`Unable to post comment: ${err}`); console.log(`Unable to post comment: ${err}`);
} }

@ -4,6 +4,7 @@ import { create as createArchiver } from "archiver";
import { join } from "path"; import { join } from "path";
import { readReport } from "../report-processor"; import { readReport } from "../report-processor";
import { getSettings } from "../settings-wrapper";
const getDatePart = (report) => { const getDatePart = (report) => {
if (!report.date) { if (!report.date) {
@ -32,7 +33,7 @@ export default (req, res, next) => {
rev: req.params.rev, 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) => { readReport(releasePath, (err, report) => {
if (err) { if (err) {

@ -3,6 +3,7 @@
import * as _ from "underscore"; import * as _ from "underscore";
import { parse } from "url"; import { parse } from "url";
import { getSettings } from "../settings-wrapper";
import { getReport } from "../status-processor"; import { getReport } from "../status-processor";
const parseOptionsFromReferer = (path, callback) => { const parseOptionsFromReferer = (path, callback) => {
@ -101,7 +102,7 @@ export const image = (req, res) => {
return handle(err, options); 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, 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) => { 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 createShowReport(res)(err, options);
} }
return getReport(req.app, options, createShowReport(res)); return getReport(req.app /* xxx */, options, createShowReport(res));
}); });

@ -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,
};

@ -5,9 +5,10 @@ import { join } from "path";
import * as _ from "underscore"; import * as _ from "underscore";
import { loadReport } from "./report-processor"; import { loadReport } from "./report-processor";
import { Settings } from "./types";
const addBranchInfo = (app, options, callback) => { const addBranchInfo = (settings: Settings, options, callback) => {
const branchFile = join(app.get("releasepath"), options.owner, options.reponame, "$revs", `${options.rev}.branch`); const branchFile = join(settings.releasepath, options.owner, options.reponame, "$revs", `${options.rev}.branch`);
exists(branchFile, (exists) => { exists(branchFile, (exists) => {
if (!exists) { if (!exists) {
@ -32,8 +33,8 @@ const addBranchInfo = (app, options, callback) => {
}); });
}; };
const addRevInfo = (app, options, callback) => { const addRevInfo = (settings: Settings, options, callback) => {
const revFile = join(app.get("releasepath"), options.owner, options.reponame, options.branch, "latest.id"); const revFile = join(settings.releasepath, options.owner, options.reponame, options.branch, "latest.id");
exists(revFile, (exists) => { exists(revFile, (exists) => {
if (!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)) { if (options.rev && !(/^[\da-f]{40}$/i).test(options.rev)) {
return callback(`Wrong rev format: ${options.rev}`, options); return callback(`Wrong rev format: ${options.rev}`, options);
} }
@ -66,14 +67,14 @@ const parseOptions = (app, options, callback) => {
}; };
if (options.rev) { if (options.rev) {
return addBranchInfo(app, { return addBranchInfo(settings, {
...result, ...result,
rev: options.rev, rev: options.rev,
}, callback); }, callback);
} }
if (/^[\da-f]{40}$/i.test(options.branchName)) { if (/^[\da-f]{40}$/i.test(options.branchName)) {
return addBranchInfo(app, { return addBranchInfo(settings, {
...result, ...result,
rev: options.branchName, rev: options.branchName,
}, callback); }, callback);
@ -81,17 +82,17 @@ const parseOptions = (app, options, callback) => {
const branchName = options.branchName || "master"; const branchName = options.branchName || "master";
return addRevInfo(app, { return addRevInfo(settings, {
...result, ...result,
branch: `refs/heads/${branchName}`, branch: `refs/heads/${branchName}`,
branchName, branchName,
}, callback); }, 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) { if (err) {
return callback(err, {}); return callback(err, {});
} }
return loadReport(app, result, callback); return loadReport(settings, result, callback);
}); });

@ -3,7 +3,7 @@
import * as _ from "underscore"; import * as _ from "underscore";
import tasks from "./tasks"; 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. // TaskProcessor does not look like EventEmitter, so no need to extend EventEmitter and use `emit' here.
const createTaskProcessor = (task: TaskInfo, outerProcessor: TaskProcessorCore, callback: TaskProcessorCallback) => { const createTaskProcessor = (task: TaskInfo, outerProcessor: TaskProcessorCore, callback: TaskProcessorCallback) => {
@ -31,6 +31,7 @@ const createTaskProcessor = (task: TaskInfo, outerProcessor: TaskProcessorCore,
onInfo, onInfo,
process: () => tasks[task.type](task.params || {}, result)(), process: () => tasks[task.type](task.params || {}, result)(),
processTask: (innerTask, innerCallback) => createTaskProcessor(innerTask, result, innerCallback).process(), processTask: (innerTask, innerCallback) => createTaskProcessor(innerTask, result, innerCallback).process(),
settings: outerProcessor.settings,
}; };
return result; return result;
@ -65,7 +66,7 @@ const addFlag = (flags) => (flagName) => {
const containsFlag = (flags) => (flagName) => 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 errors: MessagesRoot = { $allMessages: [] };
const warns: MessagesRoot = { $allMessages: [] }; const warns: MessagesRoot = { $allMessages: [] };
const infos: MessagesRoot = { $allMessages: [] }; const infos: MessagesRoot = { $allMessages: [] };
@ -86,6 +87,7 @@ export const processTask = (task, context, callback) => {
onError: messageProcessor(errors), onError: messageProcessor(errors),
onInfo: messageProcessor(infos), onInfo: messageProcessor(infos),
onWarn: messageProcessor(warns), onWarn: messageProcessor(warns),
settings,
}, (err) => callback(err, { }, (err) => callback(err, {
errors, errors,
infos, infos,

@ -4,7 +4,6 @@ import { spawn } from "child_process";
import * as JSONParse from "json-parse-safe"; import * as JSONParse from "json-parse-safe";
import { WritableStreamBuffer } from "stream-buffers"; import { WritableStreamBuffer } from "stream-buffers";
import settings from "../../settings";
import { Task } from "../types"; import { Task } from "../types";
const wrapBuilder = (builder, input, onExit) => { const wrapBuilder = (builder, input, onExit) => {
@ -46,7 +45,7 @@ const wrapBuilder = (builder, input, onExit) => {
export default ((params, processor) => () => { export default ((params, processor) => () => {
const input = JSON.stringify(params); 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}`); processor.onInfo(`DotNetBuilderWrapper processing (at ${new Date().toISOString()}): ${input}`);

@ -3,30 +3,27 @@
import { join } from "path"; import { join } from "path";
import * as _ from "underscore"; import * as _ from "underscore";
import rawSettings from "../../settings";
import { Settings, Task } from "../types"; import { Settings, Task } from "../types";
import dotnetbuilderwrapper from "./dotnetbuilderwrapper"; import dotnetbuilderwrapper from "./dotnetbuilderwrapper";
const settings: Settings = rawSettings;
export default ((params, processor) => { export default ((params, processor) => {
if (settings.isCodeAnalysisUnsupported && params.forceCodeAnalysis) { if (processor.settings.isCodeAnalysisUnsupported && params.forceCodeAnalysis) {
processor.onError("Code analysis is not supported"); processor.onError("Code analysis is not supported");
return processor.done(); return processor.done();
} }
const getAdditionalSigningParameters = () => { const getAdditionalSigningParameters = () => {
if (settings.skipCodeSigning || params.skipCodeSigning) { if (processor.settings.skipCodeSigning || params.skipCodeSigning) {
return {}; return {};
} }
return { SigningKey: settings.codeSigningKeyFile }; return { SigningKey: processor.settings.codeSigningKeyFile };
}; };
const skipCodeAnalysis = settings.isCodeAnalysisUnsupported const skipCodeAnalysis = processor.settings.isCodeAnalysisUnsupported
|| params.ignoreCodeAnalysis || params.ignoreCodeAnalysis
|| (settings.ignoreCodeAnalysisByDefault && !params.forceCodeAnalysis); || (processor.settings.ignoreCodeAnalysisByDefault && !params.forceCodeAnalysis);
const compileParams = { const compileParams = {
Configuration: params.configuration, Configuration: params.configuration,

@ -2,13 +2,12 @@
import { join } from "path"; import { join } from "path";
import settings from "../../settings";
import { Task } from "../types"; import { Task } from "../types";
import dotnetbuilderwrapper from "./dotnetbuilderwrapper"; import dotnetbuilderwrapper from "./dotnetbuilderwrapper";
export default ((params, processor) => dotnetbuilderwrapper({ export default ((params, processor) => dotnetbuilderwrapper({
ApiKey: settings.nugetApiKey, ApiKey: processor.settings.nugetApiKey,
NugetHost: settings.nugetHost, NugetHost: processor.settings.nugetHost,
Package: join(processor.context.exported, params.Package), Package: join(processor.context.exported, params.Package),
command: "nugetpush", command: "nugetpush",
}, processor)) as Task; }, processor)) as Task;

@ -5,21 +5,18 @@ import { readFile, writeFile } from "fs";
import * as glob from "glob"; import * as glob from "glob";
import { join } from "path"; import { join } from "path";
import rawSettings from "../../settings";
import { Settings, Task } from "../types"; import { Settings, Task } from "../types";
const flagDoneName = "dotnetrewriterDone"; const flagDoneName = "dotnetrewriterDone";
const settings: Settings = rawSettings;
const processAssemblyInfo = (params, processor, appendInformationalVersion) => (originalContent, cb) => { const processAssemblyInfo = (params, processor, appendInformationalVersion) => (originalContent, cb) => {
const processInternalsVisible = (content) => { const processInternalsVisible = (content) => {
if (params.skipCodeSigning || settings.skipCodeSigning) { if (params.skipCodeSigning || processor.settings.xxxskipCodeSigning) {
return content; return content;
} }
const pattern = /InternalsVisibleTo\s*\(\s*"([\w.]+)"\s*\)/g; 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); return content.replace(pattern, replacer);
}; };

@ -3,19 +3,16 @@
import { CLIEngine } from "eslint"; import { CLIEngine } from "eslint";
import { join } from "path"; import { join } from "path";
import rawSettings from "../../settings";
import { Settings, Task } from "../types"; import { Settings, Task } from "../types";
const settings: Settings = rawSettings;
const errorSeverity = 2; const errorSeverity = 2;
export default ((params, processor) => () => { export default ((params, processor) => () => {
if (settings.isCodeAnalysisUnsupported) { if (processor.settings.isCodeAnalysisUnsupported) {
return; 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 filePath = join(processor.context.exported, params.filename);
const result = cli.executeOnFiles([filePath]); const result = cli.executeOnFiles([filePath]);

@ -1,9 +1,12 @@
import { Settings } from "./settings-types";
export type TaskProcessorCallback = (err: string) => void; export type TaskProcessorCallback = (err: string) => void;
export interface ITaskProcessorCore { export interface ITaskProcessorCore {
readonly onError: (message: string | Error, prefix?: string) => void; readonly onError: (message: string | Error, prefix?: string) => void;
readonly onWarn: (message: string, prefix?: string) => void; readonly onWarn: (message: string, prefix?: string) => void;
readonly onInfo: (message: string, prefix?: string) => void; readonly onInfo: (message: string, prefix?: string) => void;
readonly settings: Settings;
readonly context?: any; readonly context?: any;
} }

Loading…
Cancel
Save