Refactoring; typing in tasks

dependabot/npm_and_yarn/BuildServer/eslint-7.2.0
Inga 🏳‍🌈 8 years ago
parent bec09d8c9f
commit 11f9cdba9b
  1. 26
      BuildServer/lib/task-processor.ts
  2. 8
      BuildServer/lib/tasks/cleanupafterdotnetbuild.ts
  3. 2
      BuildServer/lib/tasks/conditional.ts
  4. 6
      BuildServer/lib/tasks/copy.ts
  5. 8
      BuildServer/lib/tasks/copyglob.ts
  6. 6
      BuildServer/lib/tasks/cssnano.ts
  7. 8
      BuildServer/lib/tasks/cssnanoall.ts
  8. 6
      BuildServer/lib/tasks/deletefromcode.ts
  9. 6
      BuildServer/lib/tasks/dotnetbuilderwrapper.ts
  10. 8
      BuildServer/lib/tasks/dotnetcheckstyle.ts
  11. 8
      BuildServer/lib/tasks/dotnetnunitall.ts
  12. 8
      BuildServer/lib/tasks/dotnetrewrite.ts
  13. 6
      BuildServer/lib/tasks/echo.ts
  14. 6
      BuildServer/lib/tasks/eslintbrowser.ts
  15. 8
      BuildServer/lib/tasks/eslintbrowserall.ts
  16. 4
      BuildServer/lib/tasks/index.ts
  17. 2
      BuildServer/lib/tasks/noop.ts
  18. 2
      BuildServer/lib/tasks/parallel.ts
  19. 2
      BuildServer/lib/tasks/sequential.ts
  20. 6
      BuildServer/lib/tasks/uglifyjs.ts
  21. 8
      BuildServer/lib/tasks/uglifyjsall.ts
  22. 6
      BuildServer/lib/tasks/writefile.ts
  23. 8
      BuildServer/lib/tasks/zip.ts

@ -4,11 +4,8 @@ import * as _ from "underscore";
import tasks from "./tasks";
// TaskProcessor does not look like EventEmitter, so no need to extend EventEmitter and use `emit' here.
const createTaskProcessor = (task, outerProcessor: TaskProcessor, callback) => {
const result: TaskProcessor = {};
const createTaskWorker = () => tasks[task.type](task.params || {}, result);
const createTaskProcessor = (task: TaskInfo, outerProcessor: TaskProcessorCore, callback: TaskProcessorCallback) => {
const errors: string[] = [];
const process = () => createTaskWorker().process();
const getOuterPrefix = (prefix) => {
if (task.name && prefix) {
return `${task.name}/${prefix}`;
@ -22,20 +19,17 @@ const createTaskProcessor = (task, outerProcessor: TaskProcessor, callback) => {
};
const onWarn = (message, prefix) => outerProcessor.onWarn(message, getOuterPrefix(prefix));
const onInfo = (message, prefix) => outerProcessor.onInfo(message, getOuterPrefix(prefix));
const processTask = (innerTask, innerCallback) => {
const innerProcessor = createTaskProcessor(innerTask, result, innerCallback);
innerProcessor.process();
let result: TaskProcessor;
result = {
context: outerProcessor.context,
done: () => callback(errors.join("\r\n")),
onError,
onWarn,
onInfo,
process: () => tasks[task.type](task.params || {}, result)(),
processTask: (innerTask, innerCallback) => createTaskProcessor(innerTask, result, innerCallback).process(),
};
const done = () => callback(errors.join("\r\n"));
result.process = process;
result.onError = onError;
result.onWarn = onWarn;
result.onInfo = onInfo;
result.processTask = processTask;
result.done = done;
result.context = outerProcessor.context;
return result;
};

@ -2,11 +2,10 @@
import * as glob from "glob";
export default ((params, processor) => ({
process: () => glob("**/obj/{Debug,Release}/*.{dll,pdb,xml}", {
export default ((params, processor) => () => glob("**/obj/{Debug,Release}/*.{dll,pdb,xml}", {
cwd: processor.context.exported,
dot: true,
}, (err, files) => {
}, (err, files) => {
if (err) {
processor.onError(err);
@ -26,6 +25,5 @@ export default ((params, processor) => ({
})),
},
type: "parallel",
}, processor.done.bind(processor));
}),
}, processor.done);
})) as Task;

@ -5,5 +5,5 @@ export default ((params, processor) => {
&& (!params.branch || params.branch === processor.context.branch || `refs/heads/${params.branch}` === processor.context.branch);
const task = (condition && params.task) || params.otherwise;
return { process: () => processor.processTask(task || { type: "noop" }, processor.done.bind(processor)) };
return () => processor.processTask(task || { type: "noop" }, processor.done);
}) as Task;

@ -3,8 +3,7 @@
import { copy } from "fs-extra";
import { join } from "path";
export default ((params, processor) => ({
process: () => {
export default ((params, processor) => () => {
const sourceFilePath = join(processor.context.exported, params.filename);
const targetFilePath = join(processor.context.release, params.filename);
@ -19,5 +18,4 @@ export default ((params, processor) => ({
return processor.done();
});
},
})) as Task;
}) as Task;

@ -2,11 +2,10 @@
import * as glob from "glob";
export default ((params, processor) => ({
process: () => glob(params.mask, {
export default ((params, processor) => () => glob(params.mask, {
cwd: processor.context.exported,
dot: true,
}, (err, files) => {
}, (err, files) => {
if (err) {
processor.onError(err);
@ -26,6 +25,5 @@ export default ((params, processor) => ({
})),
},
type: "parallel",
}, processor.done.bind(processor));
}),
}, processor.done);
})) as Task;

@ -4,8 +4,7 @@ import { process as cssnanoProcess } from "cssnano";
import { readFile, writeFile } from "fs";
import { join } from "path";
export default ((params, processor) => ({
process: () => {
export default ((params, processor) => () => {
const filePath = join(processor.context.exported, params.filename);
readFile(filePath, (readErr, css) => {
@ -32,5 +31,4 @@ export default ((params, processor) => ({
});
});
});
},
})) as Task;
}) as Task;

@ -3,8 +3,7 @@
import * as glob from "glob";
const flagDoneName = "cssnanoallDone";
export default ((params, processor) => ({
process: () => {
export default ((params, processor) => () => {
if (processor.context.containsFlag(flagDoneName)) {
processor.onWarn("cssnanoall task is executed more than once; this is probably a bug in your mbs.json");
}
@ -30,7 +29,6 @@ export default ((params, processor) => ({
})),
},
type: (params.preventParallelTests && "sequential") || "parallel",
}, processor.done.bind(processor));
}, processor.done);
});
},
})) as Task;
}) as Task;

@ -3,8 +3,7 @@
import { remove } from "fs-extra";
import { join } from "path";
export default ((params, processor) => ({
process: () => {
export default ((params, processor) => () => {
const sourceFilePath = join(processor.context.exported, params.filename);
processor.onInfo(`Deleting ${sourceFilePath}`);
@ -18,5 +17,4 @@ export default ((params, processor) => ({
return processor.done();
});
},
})) as Task;
}) as Task;

@ -28,8 +28,7 @@ const wrapBuilder = (builder, input, onExit) => {
builder.stdin.end();
};
export default ((params, processor) => ({
process: () => {
export default ((params, processor) => () => {
const input = JSON.stringify(params);
const builder = spawn(settings.builderExecutable, [params.command]);
@ -72,5 +71,4 @@ export default ((params, processor) => ({
return processor.done();
});
},
})) as Task;
}) as Task;

@ -11,8 +11,7 @@ const autoGeneratedMarker
const flagDoneName = "dotnetcheckerDone";
export default ((params, processor) => ({
process: () => {
export default ((params, processor) => () => {
if (processor.context.containsFlag(flagDoneName)) {
return processor.done();
}
@ -70,7 +69,6 @@ export default ((params, processor) => ({
return callback();
},
)), processor.done.bind(processor));
)), processor.done);
});
},
})) as Task;
}) as Task;

@ -3,8 +3,7 @@
import * as glob from "glob";
const flagDoneName = "dotnetnunitallDone";
export default ((params, processor) => ({
process: () => {
export default ((params, processor) => () => {
if (processor.context.containsFlag(flagDoneName)) {
processor.onWarn("dotnetnunitall task is executed more than once; this is probably a bug in your mbs.json");
}
@ -36,7 +35,6 @@ export default ((params, processor) => ({
})),
},
type: (params.preventParallelTests && "sequential") || "parallel",
}, processor.done.bind(processor));
}, processor.done);
});
},
})) as Task;
}) as Task;

@ -31,8 +31,7 @@ const processAssemblyInfo = (params, processor, appendInformationalVersion) => (
return cb(null, processInformationalVersion(processInternalsVisible(originalContent)));
};
export default ((params, processor) => ({
process: () => {
export default ((params, processor) => () => {
if (processor.context.containsFlag(flagDoneName)) {
return processor.done();
}
@ -65,7 +64,6 @@ export default ((params, processor) => ({
processor.onInfo(`Rewritten file ${file}`);
}
callback(err);
})), processor.done.bind(processor));
})), processor.done);
});
},
})) as Task;
}) as Task;

@ -1,7 +1,6 @@
"use strict";
export default ((params, processor) => ({
process: () => {
export default ((params, processor) => () => {
if (params.error) {
processor.onError(params.error);
}
@ -15,5 +14,4 @@ export default ((params, processor) => ({
}
processor.done();
},
})) as Task;
}) as Task;

@ -8,8 +8,7 @@ const cli = new CLIEngine({ configFile: settings.eslintBrowserConfig });
const errorSeverity = 2;
export default ((params, processor) => ({
process: () => {
export default ((params, processor) => () => {
const filePath = join(processor.context.exported, params.filename);
const result = cli.executeOnFiles([filePath]);
@ -28,5 +27,4 @@ export default ((params, processor) => ({
});
processor.done();
},
})) as Task;
}) as Task;

@ -3,8 +3,7 @@
import * as glob from "glob";
const flagDoneName = "eslintbrowserallDone";
export default ((params, processor) => ({
process: () => {
export default ((params, processor) => () => {
if (processor.context.containsFlag(flagDoneName)) {
processor.onWarn("eslintbrowserall task is executed more than once; this is probably a bug in your mbs.json");
}
@ -32,7 +31,6 @@ export default ((params, processor) => ({
})),
},
type: (params.preventParallelTests && "sequential") || "parallel",
}, processor.done.bind(processor));
}, processor.done);
});
},
})) as Task;
}) as Task;

@ -2,7 +2,7 @@
import { readdirSync } from "fs";
const tasks: Tasks = {};
const tasks = {};
// Code taken from http://stackoverflow.com/a/17204293
readdirSync(__dirname)
@ -13,4 +13,4 @@ readdirSync(__dirname)
}
});
export default tasks;
export default tasks as Tasks;

@ -1,3 +1,3 @@
"use strict";
export default ((params, processor) => ({ process: () => processor.done() })) as Task;
export default ((params, processor) => processor.done()) as Task;

@ -4,4 +4,4 @@ import { parallel } from "async";
const mapper = (processor) => (task) => (callback) => processor.processTask(task, callback);
export default ((params, processor) => ({ process: () => parallel(params.tasks.map(mapper(processor)), () => processor.done()) })) as Task;
export default ((params, processor) => () => parallel(params.tasks.map(mapper(processor)), processor.done)) as Task;

@ -4,4 +4,4 @@ import { series } from "async";
const mapper = (processor) => (task) => (callback) => processor.processTask(task, callback);
export default ((params, processor) => ({ process: () => series(params.tasks.map(mapper(processor)), () => processor.done()) })) as Task;
export default ((params, processor) => () => series(params.tasks.map(mapper(processor)), processor.done)) as Task;

@ -4,8 +4,7 @@ import { writeFile } from "fs";
import { join, normalize } from "path";
import { minify } from "uglify-js";
export default ((params, processor) => ({
process: () => {
export default ((params, processor) => () => {
const filePath = normalize(join(processor.context.exported, params.filename));
const result = minify(filePath);
@ -18,5 +17,4 @@ export default ((params, processor) => ({
processor.done();
});
},
})) as Task;
}) as Task;

@ -4,8 +4,7 @@ import * as glob from "glob";
const doneFlagName = "uglifyjsallDone";
export default ((params, processor) => ({
process: () => {
export default ((params, processor) => () => {
if (processor.context.containsFlag(doneFlagName)) {
processor.onWarn("dotnetnunitall task is executed more than once; this is probably a bug in your mbs.json");
}
@ -31,7 +30,6 @@ export default ((params, processor) => ({
})),
},
type: (params.preventParallelTests && "sequential") || "parallel",
}, processor.done.bind(processor));
}, processor.done);
});
},
})) as Task;
}) as Task;

@ -3,8 +3,7 @@
import { writeFile } from "fs";
import { join } from "path";
export default ((params, processor) => ({
process: () => {
export default ((params, processor) => () => {
const filePath = join(processor.context.exported, params.filename);
processor.onInfo(`Writing to ${filePath}`);
@ -18,5 +17,4 @@ export default ((params, processor) => ({
return processor.done();
});
},
})) as Task;
}) as Task;

@ -4,8 +4,7 @@ import { create as createArchiver } from "archiver";
import { createWriteStream } from "fs";
import { join, normalize } from "path";
export default ((params, processor) => ({
process: () => {
export default ((params, processor) => () => {
const sourceDirectoryPath = normalize(join(processor.context.exported, String(params.directory || "")));
const targetArchivePath = normalize(join(processor.context.release, params.archive));
@ -14,11 +13,10 @@ export default ((params, processor) => ({
const output = createWriteStream(targetArchivePath);
const archive = createArchiver("zip");
output.on("close", () => processor.done());
output.on("close", processor.done);
archive.on("error", (err) => processor.onError(`Error while compressing: ${err}`));
archive.pipe(output);
archive.directory(sourceDirectoryPath, false);
archive.finalize();
},
})) as Task;
}) as Task;

Loading…
Cancel
Save