UNPKG

@factorialco/shadowdog

Version:

<img src="https://raw.githubusercontent.com/factorialco/shadowdog/refs/heads/main/logo.png" alt="drawing" width="100"/>

39 lines (38 loc) 1.24 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TaskRunner = void 0; class TaskRunner { constructor(runnerOptions) { this.runnerOptions = runnerOptions; this.middlewares = []; } use(middleware, options = {}) { this.middlewares.push({ middleware, options }); } async execute() { let result = null; let index = -1; let isAborted = false; const abort = () => { isAborted = true; }; const next = async () => { if (isAborted || ++index >= this.middlewares.length) return result; const current = this.middlewares[index]; return current.middleware({ files: this.runnerOptions.files, environment: this.runnerOptions.environment, config: this.runnerOptions.config, eventEmitter: this.runnerOptions.eventEmitter, changedFilePath: this.runnerOptions.changedFilePath, options: current.options, next, abort, }); }; result = await next(); return result; } } exports.TaskRunner = TaskRunner;