import { ILoggerProps } from './logger'; import { DepBuilder } from './dep-builder'; import { GlobalOptions, TaskContext } from './task-manager'; interface OptionConfig { default?: any; type?: any[]; } export declare type OptionDef = [string, string, OptionConfig | undefined]; export declare type TaskFn = (ctx: TaskContext) => T | Promise; export interface TaskDep { name: string; /** * Dependences are executed serially by default. * If order doesn't matter and you want better performance via parallel, you can mark it as asynchronized. * Asynchronized will run immediately whether there are synchronized tasks before them or not. * You can pass a number as the priority of asynchronized tasks, bigger is formmer. */ async?: boolean | number; /** * Whether rerun it when it occured in dependences tree more then once. */ force?: boolean; /** * Parsed options */ options?: O; resolveOptions?: (ctx: TaskContext) => Promise | O; [k: string]: any; } export declare type Dependency = TaskDep | string | DepBuilder; export interface Task extends TaskDep { namespaces: string[]; dependencies?: TaskDep[]; desc?: string; fn?: (ctx: TaskContext) => void | Promise; /** * Raw arg strings */ rawArgs: string[]; /** * @description Whether task options only allow defined options, default false * @default false */ strict?: boolean; options: O; /** * @description whether show loading * @default globalOptions.loading */ loading?: boolean; /** * @description whether log executed command * @default globalOptions.logCommand */ logCommand?: boolean; logger?: ILoggerProps; } /** * Set global options for all tasks. * @param options */ export declare function setGlobalOptions(options: GlobalOptions): void; export declare const before: (fn: (t: Task) => void | Promise) => void; export declare const after: (fn: (t: Task) => void | Promise) => void; export declare const onerror: (fn: (err: Error, t: Task) => void | Promise) => void; declare namespace TaskOptions { let last: { desc: string | undefined; optionDefs: OptionDef[]; strict: boolean | undefined; loading: boolean | undefined; }; function empty(): { desc: string | undefined; optionDefs: OptionDef[]; strict: boolean | undefined; loading: boolean | undefined; }; } /** * Define task description * @param desc */ export declare function desc(desc: string): void; /** * Define a task cli option * @param rawName * @param description * @param config */ export declare function option(rawName: string, description: string, config?: OptionConfig): void; /** * Define task cli options are strict, which means it will throw an error if you passed undefined options. */ export declare function strict(): void; /** * Set options for next task. * @param options */ export declare function setOption(options: Partial): void; export declare function task(name: string, fn: TaskFn): Task; export declare function task(name: string, dependencies: Dependency[], fn?: TaskFn): Task; /** * Create namespace prefix for inner tasks * @param ns namespace * @param fn * @example * namespace('client', ns => { * task('run', async ctx => { * logger.log(ns) // 'client' * await ctx.exec('') * }) * }) * namespace('server', ns => { * task('run', async ctx => { * logger.log(ns) // 'server' * await ctx.exec('') * }) * }) * * ========== * $ yarn foy client:run * $ yarn foy server:run */ export declare function namespace(ns: string, fn: (ns: string) => void): void; export {};