|
|
@ -1,12 +1,14 @@ |
|
|
|
"use strict"; |
|
|
|
"use strict"; |
|
|
|
|
|
|
|
|
|
|
|
import tasks from "./tasks"; |
|
|
|
import tasks from "./tasks"; |
|
|
|
import { Messages, MessagesRoot, ProcessTaskContext, ReportResult, Settings, TaskInfo, TaskProcessor, TaskProcessorCallback, TaskProcessorCore } from "./types"; |
|
|
|
import { Messages, MessagesRoot, ProcessTaskContext, ReportResult, Settings, TaskInfo, TaskInfoExternal, TaskProcessor, TaskProcessorCallback, TaskProcessorCore } from "./types"; |
|
|
|
|
|
|
|
|
|
|
|
interface IFlags { |
|
|
|
interface IFlags { |
|
|
|
[flagName: string]: boolean; |
|
|
|
[flagName: string]: boolean; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const isExternalTask = (task: TaskInfo): task is TaskInfoExternal => (task as TaskInfoExternal).type !== undefined; |
|
|
|
|
|
|
|
|
|
|
|
// 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) => { |
|
|
|
const errors: string[] = []; |
|
|
|
const errors: string[] = []; |
|
|
@ -31,7 +33,7 @@ const createTaskProcessor = (task: TaskInfo, outerProcessor: TaskProcessorCore, |
|
|
|
onError, |
|
|
|
onError, |
|
|
|
onWarn, |
|
|
|
onWarn, |
|
|
|
onInfo, |
|
|
|
onInfo, |
|
|
|
process: () => tasks[task.type](task.params || {}, result)(), |
|
|
|
process: () => (isExternalTask(task) ? tasks[task.type](task.params || {}, result) : task.task)(), |
|
|
|
processTask: (innerTask, innerCallback) => createTaskProcessor(innerTask, result, innerCallback).process(), |
|
|
|
processTask: (innerTask, innerCallback) => createTaskProcessor(innerTask, result, innerCallback).process(), |
|
|
|
settings: outerProcessor.settings, |
|
|
|
settings: outerProcessor.settings, |
|
|
|
}; |
|
|
|
}; |
|
|
|