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. 44
      BuildServer/lib/tasks/cleanupafterdotnetbuild.ts
  3. 2
      BuildServer/lib/tasks/conditional.ts
  4. 28
      BuildServer/lib/tasks/copy.ts
  5. 44
      BuildServer/lib/tasks/copyglob.ts
  6. 48
      BuildServer/lib/tasks/cssnano.ts
  7. 52
      BuildServer/lib/tasks/cssnanoall.ts
  8. 26
      BuildServer/lib/tasks/deletefromcode.ts
  9. 68
      BuildServer/lib/tasks/dotnetbuilderwrapper.ts
  10. 90
      BuildServer/lib/tasks/dotnetcheckstyle.ts
  11. 68
      BuildServer/lib/tasks/dotnetnunitall.ts
  12. 60
      BuildServer/lib/tasks/dotnetrewrite.ts
  13. 26
      BuildServer/lib/tasks/echo.ts
  14. 38
      BuildServer/lib/tasks/eslintbrowser.ts
  15. 54
      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. 26
      BuildServer/lib/tasks/uglifyjs.ts
  21. 52
      BuildServer/lib/tasks/uglifyjsall.ts
  22. 26
      BuildServer/lib/tasks/writefile.ts
  23. 26
      BuildServer/lib/tasks/zip.ts

@ -4,11 +4,8 @@ import * as _ from "underscore";
import tasks from "./tasks"; import tasks from "./tasks";
// 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, outerProcessor: TaskProcessor, callback) => { const createTaskProcessor = (task: TaskInfo, outerProcessor: TaskProcessorCore, callback: TaskProcessorCallback) => {
const result: TaskProcessor = {};
const createTaskWorker = () => tasks[task.type](task.params || {}, result);
const errors: string[] = []; const errors: string[] = [];
const process = () => createTaskWorker().process();
const getOuterPrefix = (prefix) => { const getOuterPrefix = (prefix) => {
if (task.name && prefix) { if (task.name && prefix) {
return `${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 onWarn = (message, prefix) => outerProcessor.onWarn(message, getOuterPrefix(prefix));
const onInfo = (message, prefix) => outerProcessor.onInfo(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; return result;
}; };

@ -2,30 +2,28 @@
import * as glob from "glob"; import * as glob from "glob";
export default ((params, processor) => ({ export default ((params, processor) => () => glob("**/obj/{Debug,Release}/*.{dll,pdb,xml}", {
process: () => glob("**/obj/{Debug,Release}/*.{dll,pdb,xml}", { cwd: processor.context.exported,
cwd: processor.context.exported, dot: true,
dot: true, }, (err, files) => {
}, (err, files) => { if (err) {
if (err) { processor.onError(err);
processor.onError(err);
return processor.done(); return processor.done();
} }
if (!files || !files.length) { if (!files || !files.length) {
return processor.done(); return processor.done();
} }
return processor.processTask({ return processor.processTask({
params: { params: {
tasks: files.map((file) => ({ tasks: files.map((file) => ({
name: file, name: file,
params: { filename: file }, params: { filename: file },
type: "deletefromcode", type: "deletefromcode",
})), })),
}, },
type: "parallel", type: "parallel",
}, processor.done.bind(processor)); }, processor.done);
}),
})) as Task; })) as Task;

@ -5,5 +5,5 @@ export default ((params, processor) => {
&& (!params.branch || params.branch === processor.context.branch || `refs/heads/${params.branch}` === processor.context.branch); && (!params.branch || params.branch === processor.context.branch || `refs/heads/${params.branch}` === processor.context.branch);
const task = (condition && params.task) || params.otherwise; 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; }) as Task;

@ -3,21 +3,19 @@
import { copy } from "fs-extra"; import { copy } from "fs-extra";
import { join } from "path"; import { join } from "path";
export default ((params, processor) => ({ export default ((params, processor) => () => {
process: () => { const sourceFilePath = join(processor.context.exported, params.filename);
const sourceFilePath = join(processor.context.exported, params.filename); const targetFilePath = join(processor.context.release, params.filename);
const targetFilePath = join(processor.context.release, params.filename);
processor.onInfo(`Copying ${sourceFilePath} to ${targetFilePath}`); processor.onInfo(`Copying ${sourceFilePath} to ${targetFilePath}`);
copy(sourceFilePath, targetFilePath, (err) => { copy(sourceFilePath, targetFilePath, (err) => {
if (err) { if (err) {
processor.onError(`Unable to copy file: ${err}`); processor.onError(`Unable to copy file: ${err}`);
} else { } else {
processor.onInfo("Copied file"); processor.onInfo("Copied file");
} }
return processor.done(); return processor.done();
}); });
}, }) as Task;
})) as Task;

@ -2,30 +2,28 @@
import * as glob from "glob"; import * as glob from "glob";
export default ((params, processor) => ({ export default ((params, processor) => () => glob(params.mask, {
process: () => glob(params.mask, { cwd: processor.context.exported,
cwd: processor.context.exported, dot: true,
dot: true, }, (err, files) => {
}, (err, files) => { if (err) {
if (err) { processor.onError(err);
processor.onError(err);
return processor.done(); return processor.done();
} }
if (!files || !files.length) { if (!files || !files.length) {
return processor.done(); return processor.done();
} }
return processor.processTask({ return processor.processTask({
params: { params: {
tasks: files.map((file) => ({ tasks: files.map((file) => ({
name: file, name: file,
params: { filename: file }, params: { filename: file },
type: "copy", type: "copy",
})), })),
}, },
type: "parallel", type: "parallel",
}, processor.done.bind(processor)); }, processor.done);
}),
})) as Task; })) as Task;

@ -4,33 +4,31 @@ import { process as cssnanoProcess } from "cssnano";
import { readFile, writeFile } from "fs"; import { readFile, writeFile } from "fs";
import { join } from "path"; import { join } from "path";
export default ((params, processor) => ({ export default ((params, processor) => () => {
process: () => { const filePath = join(processor.context.exported, params.filename);
const filePath = join(processor.context.exported, params.filename);
readFile(filePath, (readErr, css) => { readFile(filePath, (readErr, css) => {
if (readErr) { if (readErr) {
processor.onError(`Unable to read stylesheet ${params.filename}: ${readErr}`); processor.onError(`Unable to read stylesheet ${params.filename}: ${readErr}`);
return processor.done(); return processor.done();
} }
return cssnanoProcess(css) return cssnanoProcess(css)
.catch((cssErr) => { .catch((cssErr) => {
processor.onError(`Unable to uglify stylesheet: ${cssErr}`); processor.onError(`Unable to uglify stylesheet: ${cssErr}`);
processor.done(); processor.done();
}) })
.then((result) => { .then((result) => {
writeFile(filePath, result.css, (writeErr) => { writeFile(filePath, result.css, (writeErr) => {
if (writeErr) { if (writeErr) {
processor.onError(`Unable to write uglified stylesheet for ${params.filename}: ${writeErr}`); processor.onError(`Unable to write uglified stylesheet for ${params.filename}: ${writeErr}`);
} else { } else {
processor.onInfo(`Saved uglified stylesheet for ${params.filename}; uglified length: ${result.css.length}`); processor.onInfo(`Saved uglified stylesheet for ${params.filename}; uglified length: ${result.css.length}`);
} }
processor.done(); processor.done();
});
}); });
}); });
}, });
})) as Task; }) as Task;

@ -3,34 +3,32 @@
import * as glob from "glob"; import * as glob from "glob";
const flagDoneName = "cssnanoallDone"; const flagDoneName = "cssnanoallDone";
export default ((params, processor) => ({ export default ((params, processor) => () => {
process: () => { if (processor.context.containsFlag(flagDoneName)) {
if (processor.context.containsFlag(flagDoneName)) { processor.onWarn("cssnanoall task is executed more than once; this is probably a bug in your mbs.json");
processor.onWarn("cssnanoall task is executed more than once; this is probably a bug in your mbs.json"); }
}
processor.context.addFlag(flagDoneName); processor.context.addFlag(flagDoneName);
glob("**/*.css", { glob("**/*.css", {
cwd: processor.context.exported, cwd: processor.context.exported,
dot: true, dot: true,
}, (err, files) => { }, (err, files) => {
if (err) { if (err) {
processor.onError(err); processor.onError(err);
return processor.done(); return processor.done();
} }
return processor.processTask({ return processor.processTask({
params: { params: {
tasks: files.map((file) => ({ tasks: files.map((file) => ({
name: file, name: file,
params: { filename: file }, params: { filename: file },
type: "cssnano", type: "cssnano",
})), })),
}, },
type: (params.preventParallelTests && "sequential") || "parallel", type: (params.preventParallelTests && "sequential") || "parallel",
}, processor.done.bind(processor)); }, processor.done);
}); });
}, }) as Task;
})) as Task;

@ -3,20 +3,18 @@
import { remove } from "fs-extra"; import { remove } from "fs-extra";
import { join } from "path"; import { join } from "path";
export default ((params, processor) => ({ export default ((params, processor) => () => {
process: () => { const sourceFilePath = join(processor.context.exported, params.filename);
const sourceFilePath = join(processor.context.exported, params.filename);
processor.onInfo(`Deleting ${sourceFilePath}`); processor.onInfo(`Deleting ${sourceFilePath}`);
remove(sourceFilePath, (err) => { remove(sourceFilePath, (err) => {
if (err) { if (err) {
processor.onError(`Unable to delete file: ${err}`); processor.onError(`Unable to delete file: ${err}`);
} else { } else {
processor.onInfo("Deleted file"); processor.onInfo("Deleted file");
} }
return processor.done(); return processor.done();
}); });
}, }) as Task;
})) as Task;

@ -28,49 +28,47 @@ const wrapBuilder = (builder, input, onExit) => {
builder.stdin.end(); builder.stdin.end();
}; };
export default ((params, processor) => ({ export default ((params, processor) => () => {
process: () => { const input = JSON.stringify(params);
const input = JSON.stringify(params); const builder = spawn(settings.builderExecutable, [params.command]);
const builder = spawn(settings.builderExecutable, [params.command]);
processor.onInfo(`DotNetBuilderWrapper processing (at ${new Date().toISOString()}): ${input}`); processor.onInfo(`DotNetBuilderWrapper processing (at ${new Date().toISOString()}): ${input}`);
wrapBuilder(builder, input, (code, result, builderError) => { wrapBuilder(builder, input, (code, result, builderError) => {
if (code || builderError) { if (code || builderError) {
processor.onError(`Return code is ${code}\r\n${builderError}`); processor.onError(`Return code is ${code}\r\n${builderError}`);
return processor.done(); return processor.done();
} }
const { value, error } = JSONParse(result); const { value, error } = JSONParse(result);
if (error || !value || !value.Messages) { if (error || !value || !value.Messages) {
processor.onError(`Malformed JSON: ${error}`); processor.onError(`Malformed JSON: ${error}`);
processor.onInfo(result); processor.onInfo(result);
return processor.done(); return processor.done();
} }
const messages = value.Messages; const messages = value.Messages;
messages.forEach((message) => { messages.forEach((message) => {
if (!message) { if (!message) {
return processor.onError("Message is null"); return processor.onError("Message is null");
} }
switch (message.Type) { switch (message.Type) {
case "info": case "info":
return processor.onInfo(message.Body); return processor.onInfo(message.Body);
case "warn": case "warn":
return processor.onWarn(message.Body); return processor.onWarn(message.Body);
default: default:
return processor.onError(message.Body); return processor.onError(message.Body);
} }
}); });
processor.onInfo(`Done DotNetBuilderWrapper processing (at ${new Date().toISOString()})`); processor.onInfo(`Done DotNetBuilderWrapper processing (at ${new Date().toISOString()})`);
return processor.done(); return processor.done();
}); });
}, }) as Task;
})) as Task;

@ -11,66 +11,64 @@ const autoGeneratedMarker
const flagDoneName = "dotnetcheckerDone"; const flagDoneName = "dotnetcheckerDone";
export default ((params, processor) => ({ export default ((params, processor) => () => {
process: () => { if (processor.context.containsFlag(flagDoneName)) {
if (processor.context.containsFlag(flagDoneName)) { return processor.done();
return processor.done(); }
}
processor.context.addFlag(flagDoneName); processor.context.addFlag(flagDoneName);
return glob("**/*.cs", { cwd: processor.context.exported }, (globErr, files) => { return glob("**/*.cs", { cwd: processor.context.exported }, (globErr, files) => {
if (globErr) { if (globErr) {
processor.onError(globErr); processor.onError(globErr);
return processor.done(); return processor.done();
} }
processor.onInfo(`Found ${files.length} .cs files`);
processor.onInfo(`Found ${files.length} .cs files`); if (!files || !files.length) {
processor.onWarn("No .cs files found");
if (!files || !files.length) { return processor.done();
processor.onWarn("No .cs files found"); }
return processor.done(); const processFile = (data, file) => {
if (data.includes("\r\n")) {
return processor.onError(`Windows-style EOL (0D0A) found in file ${file}`);
} }
const processFile = (data, file) => { if (!params.ignoreCodeStyle) {
if (data.includes("\r\n")) { if (data.substr(1, autoGeneratedMarker.length) === autoGeneratedMarker || data.startsWith(autoGeneratedMarker)) {
return processor.onError(`Windows-style EOL (0D0A) found in file ${file}`); return processor.onInfo(`Skipping auto-generated file ${file}`);
} }
if (!params.ignoreCodeStyle) { if (data.includes("\t") && data.includes(" ")) {
if (data.substr(1, autoGeneratedMarker.length) === autoGeneratedMarker || data.startsWith(autoGeneratedMarker)) { processor.onError(`Both tabs and spaces found in file ${file}`);
return processor.onInfo(`Skipping auto-generated file ${file}`); }
}
if (data.includes("\t") && data.includes(" ")) {
processor.onError(`Both tabs and spaces found in file ${file}`);
}
if (data.includes("\t")) { if (data.includes("\t")) {
processor.onError(`Tabs found in file ${file}`); processor.onError(`Tabs found in file ${file}`);
}
} }
}
return processor.onInfo(`Checked file ${file}`); return processor.onInfo(`Checked file ${file}`);
}; };
return parallel(files.map((file) => (callback) => readFile( return parallel(files.map((file) => (callback) => readFile(
join(processor.context.exported, file), join(processor.context.exported, file),
{ encoding: "utf8" }, { encoding: "utf8" },
(readErr, data) => { (readErr, data) => {
if (readErr) { if (readErr) {
processor.onError(`Unable to check file ${file}: ${readErr}`); processor.onError(`Unable to check file ${file}: ${readErr}`);
return callback(readErr); return callback(readErr);
} }
processFile(data, file); processFile(data, file);
return callback(); return callback();
}, },
)), processor.done.bind(processor)); )), processor.done);
}); });
}, }) as Task;
})) as Task;

@ -3,40 +3,38 @@
import * as glob from "glob"; import * as glob from "glob";
const flagDoneName = "dotnetnunitallDone"; const flagDoneName = "dotnetnunitallDone";
export default ((params, processor) => ({ export default ((params, processor) => () => {
process: () => { if (processor.context.containsFlag(flagDoneName)) {
if (processor.context.containsFlag(flagDoneName)) { processor.onWarn("dotnetnunitall task is executed more than once; this is probably a bug in your mbs.json");
processor.onWarn("dotnetnunitall task is executed more than once; this is probably a bug in your mbs.json"); }
processor.context.addFlag(flagDoneName);
glob("**/{bin,build}/**/*.{Tests,Test,UnitTests}.dll", {
cwd: processor.context.exported,
dot: true,
}, (err, files) => {
if (err) {
processor.onError(err);
return processor.done();
}
if (!files || !files.length) {
processor.onError(`No test assemblies found in ${processor.context.exported}`);
return processor.done();
} }
processor.context.addFlag(flagDoneName); return processor.processTask({
params: {
glob("**/{bin,build}/**/*.{Tests,Test,UnitTests}.dll", { tasks: files.map((file) => ({
cwd: processor.context.exported, name: file,
dot: true, params: { assembly: file },
}, (err, files) => { type: "dotnetnunit",
if (err) { })),
processor.onError(err); },
type: (params.preventParallelTests && "sequential") || "parallel",
return processor.done(); }, processor.done);
} });
}) as Task;
if (!files || !files.length) {
processor.onError(`No test assemblies found in ${processor.context.exported}`);
return processor.done();
}
return processor.processTask({
params: {
tasks: files.map((file) => ({
name: file,
params: { assembly: file },
type: "dotnetnunit",
})),
},
type: (params.preventParallelTests && "sequential") || "parallel",
}, processor.done.bind(processor));
});
},
})) as Task;

@ -31,41 +31,39 @@ const processAssemblyInfo = (params, processor, appendInformationalVersion) => (
return cb(null, processInformationalVersion(processInternalsVisible(originalContent))); return cb(null, processInformationalVersion(processInternalsVisible(originalContent)));
}; };
export default ((params, processor) => ({ export default ((params, processor) => () => {
process: () => { if (processor.context.containsFlag(flagDoneName)) {
if (processor.context.containsFlag(flagDoneName)) { return processor.done();
return processor.done(); }
}
processor.context.addFlag(flagDoneName); processor.context.addFlag(flagDoneName);
return glob("**/{InternalsVisible,AssemblyInfo}*.cs", { cwd: processor.context.exported }, (globErr, files) => { return glob("**/{InternalsVisible,AssemblyInfo}*.cs", { cwd: processor.context.exported }, (globErr, files) => {
if (globErr) { if (globErr) {
processor.onError(globErr); processor.onError(globErr);
return processor.done(); return processor.done();
} }
processor.onInfo(`Found ${files.length} AssemblyInfo.cs files`); processor.onInfo(`Found ${files.length} AssemblyInfo.cs files`);
if (!files || !files.length) { if (!files || !files.length) {
processor.onWarn("No AssemblyInfo.cs found"); processor.onWarn("No AssemblyInfo.cs found");
return processor.done(); return processor.done();
} }
return parallel(files.map((file) => (callback) => waterfall([ return parallel(files.map((file) => (callback) => waterfall([
readFile.bind(null, join(processor.context.exported, file), { encoding: "utf8" }), readFile.bind(null, join(processor.context.exported, file), { encoding: "utf8" }),
processAssemblyInfo(params, processor, file.toLowerCase().includes("assemblyinfo.cs")), processAssemblyInfo(params, processor, file.toLowerCase().includes("assemblyinfo.cs")),
writeFile.bind(null, join(processor.context.exported, file)), writeFile.bind(null, join(processor.context.exported, file)),
], (err) => { ], (err) => {
if (err) { if (err) {
processor.onError(`Unable to rewrite file ${file}: ${err}`); processor.onError(`Unable to rewrite file ${file}: ${err}`);
} else { } else {
processor.onInfo(`Rewritten file ${file}`); processor.onInfo(`Rewritten file ${file}`);
} }
callback(err); callback(err);
})), processor.done.bind(processor)); })), processor.done);
}); });
}, }) as Task;
})) as Task;

@ -1,19 +1,17 @@
"use strict"; "use strict";
export default ((params, processor) => ({ export default ((params, processor) => () => {
process: () => { if (params.error) {
if (params.error) { processor.onError(params.error);
processor.onError(params.error); }
}
if (params.warn) { if (params.warn) {
processor.onWarn(params.warn); processor.onWarn(params.warn);
} }
if (params.info) { if (params.info) {
processor.onInfo(params.info); processor.onInfo(params.info);
} }
processor.done(); processor.done();
}, }) as Task;
})) as Task;

@ -8,25 +8,23 @@ const cli = new CLIEngine({ configFile: settings.eslintBrowserConfig });
const errorSeverity = 2; const errorSeverity = 2;
export default ((params, processor) => ({ export default ((params, processor) => () => {
process: () => { 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]);
processor.onInfo(`ESLinted ${params.filename}`);
processor.onInfo(`ESLinted ${params.filename}`);
result.results.forEach((subresult) => {
result.results.forEach((subresult) => { subresult.messages.forEach((message) => {
subresult.messages.forEach((message) => { const messageText = `${params.filename}:${message.line},${message.column} (${message.ruleId}) ${message.message}`;
const messageText = `${params.filename}:${message.line},${message.column} (${message.ruleId}) ${message.message}`;
if (message.fatal || message.severity === errorSeverity) {
if (message.fatal || message.severity === errorSeverity) { processor.onError(messageText);
processor.onError(messageText); } else {
} else { processor.onWarn(messageText);
processor.onWarn(messageText); }
}
});
}); });
});
processor.done(); processor.done();
}, }) as Task;
})) as Task;

@ -3,36 +3,34 @@
import * as glob from "glob"; import * as glob from "glob";
const flagDoneName = "eslintbrowserallDone"; const flagDoneName = "eslintbrowserallDone";
export default ((params, processor) => ({ export default ((params, processor) => () => {
process: () => { if (processor.context.containsFlag(flagDoneName)) {
if (processor.context.containsFlag(flagDoneName)) { processor.onWarn("eslintbrowserall task is executed more than once; this is probably a bug in your mbs.json");
processor.onWarn("eslintbrowserall task is executed more than once; this is probably a bug in your mbs.json"); }
}
processor.context.addFlag(flagDoneName); processor.context.addFlag(flagDoneName);
const excludeFiles = params.excludeFiles || []; const excludeFiles = params.excludeFiles || [];
glob("**/*.js", { glob("**/*.js", {
cwd: processor.context.exported, cwd: processor.context.exported,
dot: true, dot: true,
}, (err, files) => { }, (err, files) => {
if (err) { if (err) {
processor.onError(err); processor.onError(err);
return processor.done(); return processor.done();
} }
return processor.processTask({ return processor.processTask({
params: { params: {
tasks: files.filter((file) => !excludeFiles.includes(file)).map((file) => ({ tasks: files.filter((file) => !excludeFiles.includes(file)).map((file) => ({
name: file, name: file,
params: { filename: file }, params: { filename: file },
type: "eslintbrowser", type: "eslintbrowser",
})), })),
}, },
type: (params.preventParallelTests && "sequential") || "parallel", type: (params.preventParallelTests && "sequential") || "parallel",
}, processor.done.bind(processor)); }, processor.done);
}); });
}, }) as Task;
})) as Task;

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

@ -1,3 +1,3 @@
"use strict"; "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); 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); 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,19 +4,17 @@ import { writeFile } from "fs";
import { join, normalize } from "path"; import { join, normalize } from "path";
import { minify } from "uglify-js"; import { minify } from "uglify-js";
export default ((params, processor) => ({ export default ((params, processor) => () => {
process: () => { const filePath = normalize(join(processor.context.exported, params.filename));
const filePath = normalize(join(processor.context.exported, params.filename)); const result = minify(filePath);
const result = minify(filePath);
writeFile(filePath, result.code, (err) => { writeFile(filePath, result.code, (err) => {
if (err) { if (err) {
processor.onError(`Unable to write uglified script for ${params.filename}: ${err}`); processor.onError(`Unable to write uglified script for ${params.filename}: ${err}`);
} else { } else {
processor.onInfo(`Saved uglified script for ${params.filename}; uglified length: ${result.code.length}`); processor.onInfo(`Saved uglified script for ${params.filename}; uglified length: ${result.code.length}`);
} }
processor.done(); processor.done();
}); });
}, }) as Task;
})) as Task;

@ -4,34 +4,32 @@ import * as glob from "glob";
const doneFlagName = "uglifyjsallDone"; const doneFlagName = "uglifyjsallDone";
export default ((params, processor) => ({ export default ((params, processor) => () => {
process: () => { if (processor.context.containsFlag(doneFlagName)) {
if (processor.context.containsFlag(doneFlagName)) { processor.onWarn("dotnetnunitall task is executed more than once; this is probably a bug in your mbs.json");
processor.onWarn("dotnetnunitall task is executed more than once; this is probably a bug in your mbs.json"); }
}
processor.context.addFlag(doneFlagName); processor.context.addFlag(doneFlagName);
glob("**/*.js", { glob("**/*.js", {
cwd: processor.context.exported, cwd: processor.context.exported,
dot: true, dot: true,
}, (err, files) => { }, (err, files) => {
if (err) { if (err) {
processor.onError(err); processor.onError(err);
return processor.done(); return processor.done();
} }
return processor.processTask({ return processor.processTask({
params: { params: {
tasks: files.map((file) => ({ tasks: files.map((file) => ({
name: file, name: file,
params: { filename: file }, params: { filename: file },
type: "uglifyjs", type: "uglifyjs",
})), })),
}, },
type: (params.preventParallelTests && "sequential") || "parallel", type: (params.preventParallelTests && "sequential") || "parallel",
}, processor.done.bind(processor)); }, processor.done);
}); });
}, }) as Task;
})) as Task;

@ -3,20 +3,18 @@
import { writeFile } from "fs"; import { writeFile } from "fs";
import { join } from "path"; import { join } from "path";
export default ((params, processor) => ({ export default ((params, processor) => () => {
process: () => { const filePath = join(processor.context.exported, params.filename);
const filePath = join(processor.context.exported, params.filename);
processor.onInfo(`Writing to ${filePath}`); processor.onInfo(`Writing to ${filePath}`);
writeFile(filePath, params.data, (err) => { writeFile(filePath, params.data, (err) => {
if (err) { if (err) {
processor.onError(`Unable to write file: ${err}`); processor.onError(`Unable to write file: ${err}`);
} else { } else {
processor.onInfo("Written file"); processor.onInfo("Written file");
} }
return processor.done(); return processor.done();
}); });
}, }) as Task;
})) as Task;

@ -4,21 +4,19 @@ import { create as createArchiver } from "archiver";
import { createWriteStream } from "fs"; import { createWriteStream } from "fs";
import { join, normalize } from "path"; import { join, normalize } from "path";
export default ((params, processor) => ({ export default ((params, processor) => () => {
process: () => { const sourceDirectoryPath = normalize(join(processor.context.exported, String(params.directory || "")));
const sourceDirectoryPath = normalize(join(processor.context.exported, String(params.directory || ""))); const targetArchivePath = normalize(join(processor.context.release, params.archive));
const targetArchivePath = normalize(join(processor.context.release, params.archive));
processor.onInfo(`Compressing "${params.directory}" to "${params.archive}"`); processor.onInfo(`Compressing "${params.directory}" to "${params.archive}"`);
const output = createWriteStream(targetArchivePath); const output = createWriteStream(targetArchivePath);
const archive = createArchiver("zip"); 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.on("error", (err) => processor.onError(`Error while compressing: ${err}`));
archive.pipe(output); archive.pipe(output);
archive.directory(sourceDirectoryPath, false); archive.directory(sourceDirectoryPath, false);
archive.finalize(); archive.finalize();
}, }) as Task;
})) as Task;

Loading…
Cancel
Save