hereby
Version:
A simple task runner
39 lines • 1.94 kB
JavaScript
import assert from "node:assert";
/**
* A hereby Task. To get an instance, call `task`.
*/
export class Task {
/* @internal */
static create(options) {
return new Task(options);
}
// Note: private such that "private constructor();" is emitted in the d.ts files,
// which prevents extending or direct instantiation.
constructor(options) {
// Runtime typecheck; consumers of hereby may not have enabled
// typechecking, so this is helpful.
var _a, _b;
/* eslint-disable @typescript-eslint/no-unnecessary-condition */
assert.ok(typeof options.name === "string", "Task name is not a string.");
assert.ok(typeof options.description === "string" || options.description === undefined, "Task description is not a string or undefined.");
assert.ok(Array.isArray(options.dependencies) || options.dependencies === undefined, "Task dependencies is not an array or undefined.");
for (const dep of (_a = options.dependencies) !== null && _a !== void 0 ? _a : []) {
assert.ok(dep instanceof Task, "Task dependency is not a task.");
}
assert.ok(typeof options.run === "function" || options.run === undefined, "Task run is not a function or undefined.");
/* eslint-enable @typescript-eslint/no-unnecessary-condition */
// Non-type checks.
assert.ok(options.name !== "", "Task name must not be empty.");
assert.ok(!options.name.startsWith("-"), 'Task name must not start with "-".');
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
assert.ok(!!(((_b = options.dependencies) === null || _b === void 0 ? void 0 : _b.length) || options.run), "Task must have a run function or dependencies.");
this.options = options;
}
}
/**
* Creates a new Task.
*/
export function task(options) {
return Task.create(options);
}
//# sourceMappingURL=index.js.map