-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexecutor.ts
More file actions
44 lines (32 loc) · 1.08 KB
/
executor.ts
File metadata and controls
44 lines (32 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import type { EventEmitter } from 'events';
export type IExecute = {
command: string;
};
export type IExecuteResult = {
stdout: string[];
stderr: string[];
code: number;
signal?: unknown;
};
export type IExecuteStreamResult = {
code: number;
signal?: unknown;
};
export type IExecuteSimple = string;
export type CancelFunction = () => Promise<void>;
export type ExecutorConfigType = Record<string, unknown>;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export interface Executor<Config> {
executeStream?(
command: IExecuteSimple | IExecute
): Promise<[EventEmitter, CancelFunction, Promise<IExecuteStreamResult>]>;
}
export abstract class Executor<Config extends ExecutorConfigType = ExecutorConfigType> {
readonly config: Config;
constructor(config: Config) {
this.config = config;
}
abstract execute(command: IExecuteSimple): Promise<IExecuteResult>;
abstract execute({ command }: IExecute): Promise<IExecuteResult>;
abstract execute(command: IExecuteSimple | IExecute): Promise<IExecuteResult>;
}