diff --git a/BuildServer/lib/task-processor.ts b/BuildServer/lib/task-processor.ts index d107408..8623e9c 100644 --- a/BuildServer/lib/task-processor.ts +++ b/BuildServer/lib/task-processor.ts @@ -1,12 +1,14 @@ "use strict"; 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 { [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. const createTaskProcessor = (task: TaskInfo, outerProcessor: TaskProcessorCore, callback: TaskProcessorCallback) => { const errors: string[] = []; @@ -31,7 +33,7 @@ const createTaskProcessor = (task: TaskInfo, outerProcessor: TaskProcessorCore, onError, onWarn, 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(), settings: outerProcessor.settings, }; diff --git a/BuildServer/lib/types/index.ts b/BuildServer/lib/types/index.ts index dccc68b..1ded103 100644 --- a/BuildServer/lib/types/index.ts +++ b/BuildServer/lib/types/index.ts @@ -22,7 +22,9 @@ export type Settings = SettingsTypes.Settings; export type ProcessTaskContext = TaskProcessorTypes.IProcessTaskContext; export type GenericTask = TaskProcessorTypes.GenericTask; export type Task = TaskProcessorTypes.Task; -export type TaskInfo = TaskProcessorTypes.ITaskInfo; +export type TaskInfo = TaskProcessorTypes.TaskInfo; +export type TaskInfoExternal = TaskProcessorTypes.ITaskInfoExternal; +export type TaskInfoInternal = TaskProcessorTypes.ITaskInfoInternal; export type TaskProcessor = TaskProcessorTypes.ITaskProcessor; export type TaskProcessorCallback = TaskProcessorTypes.TaskProcessorCallback; export type TaskProcessorCore = TaskProcessorTypes.ITaskProcessorCore; diff --git a/BuildServer/lib/types/task-processor-types.ts b/BuildServer/lib/types/task-processor-types.ts index 373d309..b1edc2d 100644 --- a/BuildServer/lib/types/task-processor-types.ts +++ b/BuildServer/lib/types/task-processor-types.ts @@ -27,7 +27,7 @@ export interface ITaskProcessorCore { export interface ITaskProcessor extends ITaskProcessorCore { readonly process: () => void; - readonly processTask: (task: ITaskInfo, innerCallback: TaskProcessorCallback) => void; + readonly processTask: (task: TaskInfo, innerCallback: TaskProcessorCallback) => void; readonly done: () => void; } @@ -35,16 +35,25 @@ interface ITaskParameters { readonly [paramName: string]: any; } -export interface ITaskInfo { - readonly name?: string; - readonly type: string; - readonly params: ITaskParameters; -} +type TaskWithParameters = () => void; -export type GenericTask = (params: TParams, processor: ITaskProcessor) => () => void; +export type GenericTask = (params: TParams, processor: ITaskProcessor) => TaskWithParameters; export type Task = GenericTask; export interface ITasks { readonly [taskName: string]: Task; } + +export interface ITaskInfoExternal { + readonly name?: string; + readonly type: string; + readonly params?: ITaskParameters; +} + +export interface ITaskInfoInternal { + readonly name: string; + readonly task: TaskWithParameters; +} + +export type TaskInfo = ITaskInfoExternal | ITaskInfoInternal;