oak-cli/lib/server/watch.d.ts

98 lines
2.9 KiB
TypeScript

export type LogFormatterProp = {
level: "info" | "warn" | "error";
caller: NodeJS.CallSite | null;
args: any[];
};
export type LogFormatter = (props: LogFormatterProp) => any[];
export type WatchConfig = {
autoUpdateI18n?: boolean;
/**
* 是否启用polyfill
*/
polyfill?: {
/**
* 是否启用console polyfill
*/
console?: {
/**
* 是否启用
*/
enable?: boolean;
/**
* 是否打印调用堆栈信息
*/
trace?: boolean;
/**
* 格式化函数
*/
formatter: LogFormatter;
};
};
/**
* 生命周期钩子
*/
lifecycle?: {
/**
* 初始化时调用
* @returns void
*/
onInit?: (config: RealWatchConfig) => void;
/**
* 服务启动时调用
* @returns void
*/
onServerStart?: (config: RealWatchConfig) => void;
/**
* 编译前调用
* @returns void
*/
onBeforeCompile?: (config: RealWatchConfig) => void;
/**
* 编译后调用
* @returns void
*/
onAfterCompile?: (config: RealWatchConfig) => void;
/**
* 服务关闭时调用
* @returns void
*/
onServerShutdown?: (config: RealWatchConfig) => void;
/**
* 销毁监视器时调用
* @returns void
*/
onDispose?: (config: RealWatchConfig) => void;
};
};
export type FileChangeType = "add" | "remove" | "change";
export type FileChangeEvent = {
path: string;
type: FileChangeType;
timestamp: number;
};
export type CompileTask = {
id: string;
filePath: string;
changeType: FileChangeType;
timestamp: number;
};
export type CompileResult = {
taskId: string;
success: boolean;
filePath: string;
error?: string;
};
export type EventType = "file-changed" | "compile-task-added" | "compile-task-completed" | "compile-batch-started" | "compile-batch-completed" | "server-restart-needed" | "server-restarted";
export type EventHandler<T = any> = (data: T) => void | Promise<void>;
export type EventEmitter = {
on: <T>(event: EventType, handler: EventHandler<T>) => void;
emit: <T>(event: EventType, data: T) => Promise<void>;
off: <T>(event: EventType, handler: EventHandler<T>) => void;
};
type DeepRequiredIfPresent<T> = {
[P in keyof T]-?: NonNullable<T[P]> extends (...args: any) => any ? T[P] : NonNullable<T[P]> extends (infer U)[] ? DeepRequiredIfPresent<U>[] : NonNullable<T[P]> extends object ? DeepRequiredIfPresent<NonNullable<T[P]>> : T[P] extends undefined | null ? T[P] : NonNullable<T[P]>;
};
export type RealWatchConfig = DeepRequiredIfPresent<WatchConfig>;
export declare const watch: (projectPath: string, config?: WatchConfig) => Promise<() => Promise<void>>;
export {};