UNPKG

2.84 kBTypeScriptView Raw
1/// <reference types="node" />
2import { OptionConfig } from 'cac/types/Option';
3import { DepBuilder } from './dep-builder';
4import { GlobalOptions, TaskContext } from './task-manager';
5import { Writable } from 'stream';
6export declare type OptionDef = [string, string, OptionConfig | undefined];
7export declare type TaskFn<O> = (ctx: TaskContext<O>) => void | Promise<void>;
8export interface TaskDep<O = any> {
9 name: string;
10 /**
11 * Dependences are executed serially by default.
12 * If order doesn't matter and you want better performance via parallel, you can mark it as asynchronized.
13 */
14 async?: boolean;
15 /**
16 * Whether rerun it when it occured in dependences tree more then once.
17 */
18 force?: boolean;
19 /**
20 * Parsed options
21 */
22 options?: O;
23 resolveOptions?: (ctx: TaskContext) => Promise<O> | O;
24 [k: string]: any;
25}
26export declare type Dependency = TaskDep | string | DepBuilder;
27export interface Task<O = any> extends TaskDep<O> {
28 dependencies?: TaskDep[];
29 desc?: string;
30 fn?: (ctx: TaskContext<O>) => void | Promise<void>;
31 /**
32 * Raw arg strings
33 */
34 rawArgs: string[];
35 /**
36 * @description Whether task options only allow defined options, default false
37 * @default false
38 */
39 strict?: boolean;
40 options: O;
41 /**
42 * @description whether show loading
43 * @default globalOptions.loading
44 */
45 loading?: boolean;
46 /**
47 * @description whether log executed command
48 * @default globalOptions.logCommand
49 */
50 logCommand?: boolean;
51 /**
52 * @description whether redirect all ctx.exec & ctx.spawn's output to file
53 * @default globalOptions.redirectLog
54 */
55 redirectLog?: boolean | string | Writable;
56}
57/**
58 * Set global options for all tasks.
59 * @param options
60 */
61export declare function setGlobalOptions(options: GlobalOptions): void;
62declare namespace TaskOptions {
63 let last: {
64 desc: string | undefined;
65 optionDefs: [string, string, OptionConfig | undefined][];
66 strict: boolean | undefined;
67 loading: boolean | undefined;
68 };
69 function empty(): {
70 desc: string | undefined;
71 optionDefs: [string, string, OptionConfig | undefined][];
72 strict: boolean | undefined;
73 loading: boolean | undefined;
74 };
75}
76export declare function desc(desc: string): void;
77export declare function option(rawName: string, description: string, config?: OptionConfig): void;
78export declare function strict(): void;
79/**
80 * Set options for next task.
81 * @param options
82 */
83export declare function setOption(options: Partial<typeof TaskOptions.last>): void;
84export declare function task<O>(name: string, fn: TaskFn<O>): Task<O>;
85export declare function task<O>(name: string, dependencies: Dependency[], fn?: TaskFn<O>): Task<O>;
86export {};