1 |
|
2 |
|
3 |
|
4 | export class Task {
|
5 |
|
6 | static create(options) {
|
7 | return new Task(options);
|
8 | }
|
9 |
|
10 |
|
11 | constructor(options) {
|
12 |
|
13 |
|
14 | var _a;
|
15 | if (typeof options.name !== "string") {
|
16 | throw new TypeError("Task name is not a string.");
|
17 | }
|
18 | if (typeof options.description !== "string" && options.description !== undefined) {
|
19 | throw new TypeError("Task description is not a string or undefined.");
|
20 | }
|
21 | if (!Array.isArray(options.dependencies) && options.dependencies !== undefined) {
|
22 | throw new TypeError("Task dependencies is not an array or undefined.");
|
23 | }
|
24 | if (options.dependencies) {
|
25 | for (const dep of options.dependencies) {
|
26 | if (!(dep instanceof Task)) {
|
27 | throw new TypeError("Task dependency is not a task.");
|
28 | }
|
29 | }
|
30 | }
|
31 | if (typeof options.run !== "function" && options.run !== undefined) {
|
32 | throw new TypeError("Task run is not a function or undefined.");
|
33 | }
|
34 |
|
35 | if (!options.name) {
|
36 | throw new Error("Task name must not be empty.");
|
37 | }
|
38 | if (options.name.startsWith("-")) {
|
39 | throw new Error('Task name must not start with "-".');
|
40 | }
|
41 | if (!((_a = options.dependencies) === null || _a === void 0 ? void 0 : _a.length) && !options.run) {
|
42 | throw new Error("Task must have a run function or dependencies.");
|
43 | }
|
44 | this.options = options;
|
45 | }
|
46 | }
|
47 |
|
48 |
|
49 |
|
50 | export function task(options) {
|
51 | return Task.create(options);
|
52 | }
|
53 |
|
\ | No newline at end of file |