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";
// 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,30 +2,28 @@
import * as glob from "glob";
export default ((params, processor) => ({
process: () => glob("**/obj/{Debug,Release}/*.{dll,pdb,xml}", {
cwd: processor.context.exported,
dot: true,
}, (err, files) => {
if (err) {
processor.onError(err);
export default ((params, processor) => () => glob("**/obj/{Debug,Release}/*.{dll,pdb,xml}", {
cwd: processor.context.exported,
dot: true,
}, (err, files) => {
if (err) {
processor.onError(err);
return processor.done();
}
return processor.done();
}
if (!files || !files.length) {
return processor.done();
}
if (!files || !files.length) {
return processor.done();
}
return processor.processTask({
params: {
tasks: files.map((file) => ({
name: file,
params: { filename: file },
type: "deletefromcode",
})),
},
type: "parallel",
}, processor.done.bind(processor));
}),
return processor.processTask({
params: {
tasks: files.map((file) => ({
name: file,
params: { filename: file },
type: "deletefromcode",
})),
},
type: "parallel",
}, 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,21 +3,19 @@
import { copy } from "fs-extra";
import { join } from "path";
export default ((params, processor) => ({
process: () => {
const sourceFilePath = join(processor.context.exported, params.filename);
const targetFilePath = join(processor.context.release, params.filename);
export default ((params, processor) => () => {
const sourceFilePath = join(processor.context.exported, 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) => {
if (err) {
processor.onError(`Unable to copy file: ${err}`);
} else {
processor.onInfo("Copied file");
}
copy(sourceFilePath, targetFilePath, (err) => {
if (err) {
processor.onError(`Unable to copy file: ${err}`);
} else {
processor.onInfo("Copied file");
}
return processor.done();
});
},
})) as Task;
return processor.done();
});
}) as Task;

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

@ -4,33 +4,31 @@ import { process as cssnanoProcess } from "cssnano";
import { readFile, writeFile } from "fs";
import { join } from "path";
export default ((params, processor) => ({
process: () => {
const filePath = join(processor.context.exported, params.filename);
export default ((params, processor) => () => {
const filePath = join(processor.context.exported, params.filename);
readFile(filePath, (readErr, css) => {
if (readErr) {
processor.onError(`Unable to read stylesheet ${params.filename}: ${readErr}`);
readFile(filePath, (readErr, css) => {
if (readErr) {
processor.onError(`Unable to read stylesheet ${params.filename}: ${readErr}`);
return processor.done();
}
return processor.done();
}
return cssnanoProcess(css)
.catch((cssErr) => {
processor.onError(`Unable to uglify stylesheet: ${cssErr}`);
processor.done();
})
.then((result) => {
writeFile(filePath, result.css, (writeErr) => {
if (writeErr) {
processor.onError(`Unable to write uglified stylesheet for ${params.filename}: ${writeErr}`);
} else {
processor.onInfo(`Saved uglified stylesheet for ${params.filename}; uglified length: ${result.css.length}`);
}
return cssnanoProcess(css)
.catch((cssErr) => {
processor.onError(`Unable to uglify stylesheet: ${cssErr}`);
processor.done();
})
.then((result) => {
writeFile(filePath, result.css, (writeErr) => {
if (writeErr) {
processor.onError(`Unable to write uglified stylesheet for ${params.filename}: ${writeErr}`);
} else {
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";
const flagDoneName = "cssnanoallDone";
export default ((params, processor) => ({
process: () => {
if (processor.context.containsFlag(flagDoneName)) {
processor.onWarn("cssnanoall task is executed more than once; this is probably a bug in your mbs.json");
}
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");
}
processor.context.addFlag(flagDoneName);
processor.context.addFlag(flagDoneName);
glob("**/*.css", {
cwd: processor.context.exported,
dot: true,
}, (err, files) => {
if (err) {
processor.onError(err);
glob("**/*.css", {
cwd: processor.context.exported,
dot: true,
}, (err, files) => {
if (err) {
processor.onError(err);
return processor.done();
}
return processor.done();
}
return processor.processTask({
params: {
tasks: files.map((file) => ({
name: file,
params: { filename: file },
type: "cssnano",
})),
},
type: (params.preventParallelTests && "sequential") || "parallel",
}, processor.done.bind(processor));
});
},
})) as Task;
return processor.processTask({
params: {
tasks: files.map((file) => ({
name: file,
params: { filename: file },
type: "cssnano",
})),
},
type: (params.preventParallelTests && "sequential") || "parallel",
}, processor.done);
});
}) as Task;

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

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

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

@ -3,40 +3,38 @@
import * as glob from "glob";
const flagDoneName = "dotnetnunitallDone";
export default ((params, processor) => ({
process: () => {
if (processor.context.containsFlag(flagDoneName)) {
processor.onWarn("dotnetnunitall task is executed more than once; this is probably a bug in your mbs.json");
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");
}
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);
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();
}
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;
return processor.processTask({
params: {
tasks: files.map((file) => ({
name: file,
params: { assembly: file },
type: "dotnetnunit",
})),
},
type: (params.preventParallelTests && "sequential") || "parallel",
}, processor.done);
});
}) as Task;

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

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

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

@ -3,36 +3,34 @@
import * as glob from "glob";
const flagDoneName = "eslintbrowserallDone";
export default ((params, processor) => ({
process: () => {
if (processor.context.containsFlag(flagDoneName)) {
processor.onWarn("eslintbrowserall task is executed more than once; this is probably a bug in your mbs.json");
}
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");
}
processor.context.addFlag(flagDoneName);
processor.context.addFlag(flagDoneName);
const excludeFiles = params.excludeFiles || [];
const excludeFiles = params.excludeFiles || [];
glob("**/*.js", {
cwd: processor.context.exported,
dot: true,
}, (err, files) => {
if (err) {
processor.onError(err);
glob("**/*.js", {
cwd: processor.context.exported,
dot: true,
}, (err, files) => {
if (err) {
processor.onError(err);
return processor.done();
}
return processor.done();
}
return processor.processTask({
params: {
tasks: files.filter((file) => !excludeFiles.includes(file)).map((file) => ({
name: file,
params: { filename: file },
type: "eslintbrowser",
})),
},
type: (params.preventParallelTests && "sequential") || "parallel",
}, processor.done.bind(processor));
});
},
})) as Task;
return processor.processTask({
params: {
tasks: files.filter((file) => !excludeFiles.includes(file)).map((file) => ({
name: file,
params: { filename: file },
type: "eslintbrowser",
})),
},
type: (params.preventParallelTests && "sequential") || "parallel",
}, processor.done);
});
}) 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,19 +4,17 @@ import { writeFile } from "fs";
import { join, normalize } from "path";
import { minify } from "uglify-js";
export default ((params, processor) => ({
process: () => {
const filePath = normalize(join(processor.context.exported, params.filename));
const result = minify(filePath);
export default ((params, processor) => () => {
const filePath = normalize(join(processor.context.exported, params.filename));
const result = minify(filePath);
writeFile(filePath, result.code, (err) => {
if (err) {
processor.onError(`Unable to write uglified script for ${params.filename}: ${err}`);
} else {
processor.onInfo(`Saved uglified script for ${params.filename}; uglified length: ${result.code.length}`);
}
writeFile(filePath, result.code, (err) => {
if (err) {
processor.onError(`Unable to write uglified script for ${params.filename}: ${err}`);
} else {
processor.onInfo(`Saved uglified script for ${params.filename}; uglified length: ${result.code.length}`);
}
processor.done();
});
},
})) as Task;
processor.done();
});
}) as Task;

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

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

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

Loading…
Cancel
Save