UNPKG

2 kBJavaScriptView Raw
1/**
2 * A hereby Task. To get an instance, call `test`.
3 */
4export class Task {
5 /* @internal */
6 static create(options) {
7 return new Task(options);
8 }
9 // Note: private such that "private constructor();" is emitted in the d.ts files,
10 // which prevents extending or direct instantiation.
11 constructor(options) {
12 // Runtime typecheck; consumers of hereby may not have enabled
13 // typechecking, so this is helpful.
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 // Non-type checks.
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 * Creates a new Task.
49 */
50export function task(options) {
51 return Task.create(options);
52}
53//# sourceMappingURL=index.js.map
\No newline at end of file