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