kist
Version:
Lightweight Package Pipeline Processor with Plugin Architecture
41 lines • 1.69 kB
JavaScript
import { __awaiter } from "tslib";
import { AbstractProcess } from "../abstract/AbstractProcess.js";
import { ActionRegistry } from "./ActionRegistry.js";
export class Step extends AbstractProcess {
constructor(step) {
super();
this.name = step.name;
const actionRegistry = ActionRegistry.getInstance();
const ActionClass = actionRegistry.getAction(String(step.action));
if (!ActionClass) {
const msg = `
Unknown action "${step.action}" for step "${this.name}".
Ensure the action is registered in the registry.
`;
this.logError(msg);
throw new Error(msg);
}
this.action = new ActionClass();
this.options = step.options;
this.logInfo(`Step "${this.name}" initialized with action "${step.action.constructor.name}".`);
}
execute() {
return __awaiter(this, void 0, void 0, function* () {
this.logInfo(`Executing step: ${this.name}`);
try {
if (typeof this.action.validateOptions === "function") {
const isValid = this.action.validateOptions(this.options || {});
if (!isValid) {
throw new Error(`Invalid options for step: ${this.name}`);
}
}
yield this.action.execute(this.options || {});
this.logInfo(`Step "${this.name}" completed successfully.`);
}
catch (error) {
this.logError(`Error executing step "${this.name}": ${error}`, error);
}
});
}
}
//# sourceMappingURL=Step.js.map