Implemented InternalTaskInfo

dependabot/npm_and_yarn/BuildServer/eslint-7.2.0
Inga 🏳‍🌈 8 years ago
parent 26137d503a
commit 65f55220b2
  1. 6
      BuildServer/lib/task-processor.ts
  2. 4
      BuildServer/lib/types/index.ts
  3. 23
      BuildServer/lib/types/task-processor-types.ts

@ -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,
}; };

@ -22,7 +22,9 @@ export type Settings = SettingsTypes.Settings;
export type ProcessTaskContext = TaskProcessorTypes.IProcessTaskContext; export type ProcessTaskContext = TaskProcessorTypes.IProcessTaskContext;
export type GenericTask<TParams> = TaskProcessorTypes.GenericTask<TParams>; export type GenericTask<TParams> = TaskProcessorTypes.GenericTask<TParams>;
export type Task = TaskProcessorTypes.Task; 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 TaskProcessor = TaskProcessorTypes.ITaskProcessor;
export type TaskProcessorCallback = TaskProcessorTypes.TaskProcessorCallback; export type TaskProcessorCallback = TaskProcessorTypes.TaskProcessorCallback;
export type TaskProcessorCore = TaskProcessorTypes.ITaskProcessorCore; export type TaskProcessorCore = TaskProcessorTypes.ITaskProcessorCore;

@ -27,7 +27,7 @@ export interface ITaskProcessorCore {
export interface ITaskProcessor extends ITaskProcessorCore { export interface ITaskProcessor extends ITaskProcessorCore {
readonly process: () => void; readonly process: () => void;
readonly processTask: (task: ITaskInfo, innerCallback: TaskProcessorCallback) => void; readonly processTask: (task: TaskInfo, innerCallback: TaskProcessorCallback) => void;
readonly done: () => void; readonly done: () => void;
} }
@ -35,16 +35,25 @@ interface ITaskParameters {
readonly [paramName: string]: any; readonly [paramName: string]: any;
} }
export interface ITaskInfo { type TaskWithParameters = () => void;
readonly name?: string;
readonly type: string;
readonly params: ITaskParameters;
}
export type GenericTask<TParams> = (params: TParams, processor: ITaskProcessor) => () => void; export type GenericTask<TParams> = (params: TParams, processor: ITaskProcessor) => TaskWithParameters;
export type Task = GenericTask<ITaskParameters>; export type Task = GenericTask<ITaskParameters>;
export interface ITasks { export interface ITasks {
readonly [taskName: string]: Task; 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;

Loading…
Cancel
Save