import commander from 'commander'; import { EventEmitter } from 'node:events'; import * as utils from '@fesjs/utils'; /** * 插件类型枚举 */ declare enum PluginType { preset = "preset", plugin = "plugin", builder = "builder" } /** * 服务阶段枚举 */ declare enum ServiceStage { uninitialized = 0, constructor = 1, init = 2, initPresets = 3, initPlugins = 4, initHooks = 5, pluginReady = 6, getConfig = 7, getPaths = 8, run = 9 } /** * 配置变更类型枚举 */ declare enum ConfigChangeType { reload = "reload", regenerateTmpFiles = "regenerateTmpFiles" } /** * 应用插件类型枚举 */ declare enum ApplyPluginsType { add = "add", modify = "modify", event = "event" } /** * 启用方式枚举 */ declare enum EnableBy { register = "register", config = "config" } interface PluginAPIOptions { id: string; key: string; service: ServiceInstance; } interface DescribeOptions { id?: string; key?: string; config?: PluginConfig; enableBy?: EnableBy | (() => boolean); } declare class PluginAPI { id: string; key: string; service: ServiceInstance; utils: typeof utils; logger: typeof utils.logger; constructor(opts: PluginAPIOptions); describe({ id, key, config, enableBy }?: DescribeOptions): void; register(hook: Hook): void; registerCommand(commandOption: CommandOption): void; registerPlugins(plugins: (string | Plugin)[]): Promise; registerPresets(presets: (string | Plugin)[]): Promise; registerMethod({ name, fn, exitsError }: { name: string; fn?: (...args: any[]) => any; exitsError: boolean; }): void; registerBuilder(builder: Record): void; skipPlugins(pluginIds: string[]): void; } interface ServiceOptions { cwd?: string; pkg?: Record; env?: string; fesPkg?: Record; presets?: string[]; plugins?: string[]; } interface SetupOptions { presets?: string[]; plugins?: string[]; } interface ApplyAPIOptions { apply: () => Promise | any; api: any; } interface ApplyPluginsOptionsExtended extends ApplyPluginsOptions { args?: any; } interface RunOptions { rawArgv?: Record; args?: Record; } interface RunCommandOptions { rawArgv?: Record; args?: Record; } declare class Service extends EventEmitter { cwd: string; pkg: Record; skipPluginIds: Set; stage: ServiceStage; commands: Record; plugins: Record; builder: Record; pluginMethods: Record void>; initialPresets: Plugin[]; initialPlugins: Plugin[]; _extraPresets: Plugin[]; _extraPlugins: Plugin[]; userConfig: UserConfig; configInstance: ConfigInstance; config: UserConfig | null; hooksByPluginId: Record; hooks: Record; paths: Paths; env: string; ApplyPluginsType: typeof ApplyPluginsType; EnableBy: typeof EnableBy; ConfigChangeType: typeof ConfigChangeType; ServiceStage: typeof ServiceStage; args: Record | undefined; fesPkg: Record; program: commander.Command; ready: Promise; constructor(opts: ServiceOptions); setup(opts: SetupOptions): Promise; setStage(stage: ServiceStage): void; resolvePackage(): Record; loadEnv(): void; init(): Promise; setConfig(): Promise; initPresetsAndPlugins(): Promise; getPluginAPI(opts: { id: string; key: string; service: Service; }): PluginAPI; applyAPI(opts: ApplyAPIOptions): Promise; initPreset(preset: Plugin): Promise; initPlugin(plugin: Plugin): Promise; getPluginOptsWithKey(key: string): any; registerPlugin(plugin: Plugin): void; isPluginEnable(pluginId: string): boolean; hasPresets(presetIds: string[]): boolean; hasPlugins(pluginIds: string[]): boolean; applyPlugins(opts: ApplyPluginsOptionsExtended): Promise; initCommand(): commander.Command; run({ rawArgv, args }: RunOptions): Promise; runCommand({ rawArgv, args }: RunCommandOptions): Promise; parseCommand(): Promise; } type ConfigInstance = InstanceType; type ServiceInstance = InstanceType; type PluginAPIInstance = InstanceType; interface UserConfig { [key: string]: any; } interface Paths { tmpDir: string; cwd: string; absNodeModulesPath: string; absOutputPath: string; absSrcPath: string; absPagesPath: string; absTmpPath: string; } interface Plugin { id: string; key: string; path: string; apply: () => Promise | any; config?: PluginConfig; enableBy?: EnableBy | (() => boolean); isPreset?: boolean; defaultConfig: any; } interface PluginConfig { schema?: (joi: any) => any; default?: any; } interface Hook { key: string; fn: (...args: any[]) => any; pluginId?: string; stage?: number; before?: string; } interface CommandOption { command: string; description: string; options?: CommandOptionConfig[]; fn?: (args: CommandArgs) => Promise | void; } interface CommandOptionConfig { name: string; description: string; default?: any; choices?: string[]; } interface CommandArgs { rawArgv: Record; args: Record; options: Record; program: any; } interface ApplyPluginsOptions { key: string; type: ApplyPluginsType; initialValue?: any; args?: any; } interface ConfigOptions { cwd?: string; service: ServiceInstance; localConfig?: boolean; } interface WatchOptions { userConfig: UserConfig; onChange: (params: { userConfig: UserConfig; pluginChanged: Array<{ key: string; pluginId: string; }>; valueChanged: Array<{ key: string; pluginId: string; }>; }) => void; } declare class Config { cwd: string; service: ServiceInstance; config: any; localConfig: boolean; configFile: string[]; constructor(opts: ConfigOptions); getDefaultConfig(): Promise>; getConfig(defaultConfig: Record): Promise; getUserConfig(): Promise; addAffix(file: string, affix: string): string; requireConfigs(configFiles: string[]): Promise; mergeConfig(configs: any[]): UserConfig; getConfigFile(): string[]; getWatchFilesAndDirectories(): string[]; watch(opts: WatchOptions): () => void; } export { Config as C, PluginType as P, Service as S, type ConfigInstance as a, type PluginAPIInstance as b, type ServiceInstance as c };