1 |
|
2 | import { AsyncTask } from "async-done";
|
3 | import { EventEmitter } from "events";
|
4 | import * as Registry from "undertaker-registry";
|
5 |
|
6 | declare namespace Undertaker {
|
7 | interface TaskFunctionParams {
|
8 | readonly name?: string | undefined;
|
9 | displayName?: string | undefined;
|
10 | description?: string | undefined;
|
11 | flags?: TaskFlags | undefined;
|
12 | }
|
13 |
|
14 | interface TaskFlags {
|
15 | [arg: string]: string;
|
16 | }
|
17 |
|
18 | interface TaskCallback {
|
19 | (error?: Error | null): void;
|
20 | }
|
21 |
|
22 | interface TaskFunctionBase {
|
23 | (done: TaskCallback): ReturnType<AsyncTask>;
|
24 | }
|
25 |
|
26 | interface TaskFunction extends TaskFunctionBase, TaskFunctionParams {}
|
27 |
|
28 | type Task = string | TaskFunction;
|
29 |
|
30 | interface TaskFunctionWrapped extends TaskFunctionBase {
|
31 | displayName: string;
|
32 | unwrap(): TaskFunction;
|
33 | }
|
34 |
|
35 | interface TreeOptions {
|
36 | |
37 |
|
38 |
|
39 |
|
40 | deep?: boolean | undefined;
|
41 | }
|
42 |
|
43 | interface TreeResult {
|
44 | label: "Tasks";
|
45 | nodes: Node[];
|
46 | }
|
47 |
|
48 | interface Node {
|
49 | label: string;
|
50 | nodes: Node[];
|
51 | type?: string | undefined;
|
52 | branch?: boolean | undefined;
|
53 | }
|
54 | }
|
55 |
|
56 | declare class Undertaker extends EventEmitter {
|
57 | constructor(registry?: Registry);
|
58 |
|
59 | /**
|
60 | * Returns the wrapped registered function.
|
61 | * @param taskName - Task name.
|
62 | */
|
63 | task(taskName: string): Undertaker.TaskFunctionWrapped | undefined;
|
64 |
|
65 | /**
|
66 | * Register the task by the taskName.
|
67 | * @param taskName - Task name.
|
68 | * @param fn - Task function.
|
69 | */
|
70 | task(taskName: string, fn: Undertaker.TaskFunction): void;
|
71 |
|
72 | /**
|
73 | * Register the task by the name property of the function.
|
74 | * @param fn - Task function.
|
75 | */
|
76 | task(fn: Undertaker.TaskFunction): void;
|
77 |
|
78 | /**
|
79 | * Takes a variable amount of strings (taskName) and/or functions (fn)
|
80 | * and returns a function of the composed tasks or functions.
|
81 | * Any taskNames are retrieved from the registry using the get method.
|
82 | *
|
83 | * When the returned function is executed, the tasks or functions will be executed in series,
|
84 | * each waiting for the prior to finish. If an error occurs, execution will stop.
|
85 | * @param tasks - List of tasks.
|
86 | */
|
87 | series(...tasks: Undertaker.Task[]): Undertaker.TaskFunction;
|
88 |
|
89 | /**
|
90 | * Takes a variable amount of strings (taskName) and/or functions (fn)
|
91 | * and returns a function of the composed tasks or functions.
|
92 | * Any taskNames are retrieved from the registry using the get method.
|
93 | *
|
94 | * When the returned function is executed, the tasks or functions will be executed in series,
|
95 | * each waiting for the prior to finish. If an error occurs, execution will stop.
|
96 | * @param tasks - List of tasks.
|
97 | */
|
98 | series(tasks: Undertaker.Task[]): Undertaker.TaskFunction;
|
99 |
|
100 | /**
|
101 | * Takes a variable amount of strings (taskName) and/or functions (fn)
|
102 | * and returns a function of the composed tasks or functions.
|
103 | * Any taskNames are retrieved from the registry using the get method.
|
104 | *
|
105 | * When the returned function is executed, the tasks or functions will be executed in parallel,
|
106 | * all being executed at the same time. If an error occurs, all execution will complete.
|
107 | * @param tasks - list of tasks.
|
108 | */
|
109 | parallel(...tasks: Undertaker.Task[]): Undertaker.TaskFunction;
|
110 |
|
111 | /**
|
112 | * Takes a variable amount of strings (taskName) and/or functions (fn)
|
113 | * and returns a function of the composed tasks or functions.
|
114 | * Any taskNames are retrieved from the registry using the get method.
|
115 | *
|
116 | * When the returned function is executed, the tasks or functions will be executed in parallel,
|
117 | * all being executed at the same time. If an error occurs, all execution will complete.
|
118 | * @param tasks - list of tasks.
|
119 | */
|
120 | parallel(tasks: Undertaker.Task[]): Undertaker.TaskFunction;
|
121 |
|
122 | /**
|
123 | * Returns the current registry object.
|
124 | */
|
125 | registry(): Registry;
|
126 |
|
127 | /**
|
128 | * The tasks from the current registry will be transferred to it
|
129 | * and the current registry will be replaced with the new registry.
|
130 | * @param registry - Instance of registry.
|
131 | */
|
132 | registry(registry: Registry): void;
|
133 |
|
134 | /**
|
135 | * Optionally takes an object (options) and returns an object representing the tree of registered tasks.
|
136 | * @param options - Tree options.
|
137 | */
|
138 | tree(options?: Undertaker.TreeOptions): Undertaker.TreeResult;
|
139 |
|
140 | /**
|
141 | * Takes a string or function (task) and returns a timestamp of the last time the task was run successfully.
|
142 | * The time will be the time the task started. Returns undefined if the task has not been run.
|
143 | * @param task - Task.
|
144 | * @param [timeResolution] - Time resolution.
|
145 | */
|
146 | lastRun(task: Undertaker.Task, timeResolution?: number): number;
|
147 | }
|
148 |
|
149 | export = Undertaker;
|