๐Ÿ“ฆ directus / cli

๐Ÿ“„ events.ts ยท 26 lines
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
26import { Command } from './command';
import { IOutput } from './output';

export type Listener<T = any, P = any, R = any> =
	| ((...args: P[]) => Promise<R>)
	| ((...args: P[]) => R)
	| ((this: T, ...args: P[]) => Promise<R>)
	| ((this: T, ...args: P[]) => R);

export type EventTypes = {
	'command.initialize.before': (command: Command) => void | Promise<void>;
	'command.initialize.after': (command: Command) => void | Promise<void>;

	'command.execute.before': (command: Command, options: any) => void | Promise<void>;
	'command.execute.after': (command: Command) => void | Promise<void>;

	'command.options.register': (command: Command) => void;

	'output.formats.register': (output: IOutput) => void;
};

export interface IEvents {
	on<E extends keyof EventTypes>(event: E, listener: EventTypes[E]): void;
	emit<E extends keyof EventTypes>(event: E, ...args: Parameters<EventTypes[E]>): Promise<void>;
}