UNPKG

takin

Version:

Front end engineering base toolchain and scaffold

90 lines (89 loc) 3.35 kB
import { AsyncSeriesHook, AsyncSeriesWaterfallHook, SyncWaterfallHook } from 'tapable'; import { CommandOptions } from './cli'; import { Config, PluginOption } from './config'; import { Runner, RunnerContext, RunnerOptions } from './runner'; import { UserConfig } from './types'; export interface TakinHooks { /** * 完成初始化之后并开始运行 run 命令之前执行 */ initialize: AsyncSeriesHook<[Takin]>; /** * 前置准备阶段: 可在这个阶段做一些前期准备, 可在这个阶段通过插件来做前期功能干预 * 注: 这个阶段是通过一个单独的 Runner 运行出来的 * 通过 RunnerOptions 传入的插件是独立的且仅用于 prepare 阶段 */ prepare: AsyncSeriesHook<RunnerOptions>; /** * 配置文件载入完成, 可在这个阶段修改整体配置 * 如果配置通过 run 方法直接传入则该 hook 不会执行 */ configLoaded: AsyncSeriesHook<[Takin, CommandOptions]>; /** * 配置完成筛选, 可在这个阶段调整需要运行的用户配置 */ configFiltered: AsyncSeriesWaterfallHook<[UserConfig[], CommandOptions]>; /** * runner 扩展阶段, 可在这个阶段定制 Runner */ extendRunner: SyncWaterfallHook<[typeof Runner, RunnerOptions]>; } /** * 命令行扩展内核,基于 Runner 和 Plugin * 提供各类 Utils 方法 */ export declare class Takin extends Config { /** * 配置实例, 已废弃 * @deprecated takin 已直接继承 Config 类, config 的相关方法或属性调用请直接使用 takin 实例 */ readonly config: Config; /** * takin hooks */ readonly hooks: TakinHooks; private isConfigLoaded; private isReloading; private lastRunState?; /** * 当前执行的 runner */ private currentRunners; constructor(name?: string); /** * 应用 Runner 插件 */ use(plugins: PluginOption[]): void; /** * 执行命令, 分为如下几个步骤 * 1. 执行初始化 hook * 2. 尝试载入配置文件, 只执行一次 * 3. 基于多配置的设定,获取 filters * 4. 基于 filters 筛选 用户配置 * 5. 基于不同的用户配置分别运行 Runner * @param command - 命令参数, 可选, 如不填写则自动从命令行读取 * @param userConfigs - 用户配置, 可选, 如不填写则使用 config 中载入的用户配置 * @param context - Runner 上下文, 可用于初始化时候传入 Runner * @returns 返回命令执行的结果 */ run<R = any>(command?: CommandOptions, userConfigs?: UserConfig[], context?: RunnerContext | Record<string, any>): Promise<(R | undefined)[]>; /** * 基于最近一次命令传入参数重新运行命令 * @returns 返回命令执行的结果 */ reload<R = any>(): Promise<(R | undefined)[]>; /** * 执行扩展 Runner 方法 */ private runExtendedRunner; /** * 利用 Runner 的能力完成一些前置准备工作 * - 修改 cwd * - 载入用户配置文件 * - 过滤用户配置 * @param command - 通过接口传入的命令选项 * @param userConfigs - 通过接口传入的用户配置 * @returns 过滤后的用户配置数组 */ private prepare; }