UNPKG

kist

Version:

Lightweight Package Pipeline Processor with Plugin Architecture

97 lines 3.68 kB
import { __awaiter } from "tslib"; import { spawn } from "child_process"; import path from "path"; import { AbstractProcess } from "../abstract/AbstractProcess.js"; import { ConfigStore } from "../config/ConfigStore.js"; import { Pipeline } from "./Pipeline.js"; export class PipelineManager extends AbstractProcess { constructor(liveServer) { super(); this.liveServer = liveServer; this.pipelineProcess = null; this.isRestarting = false; this.logInfo("PipelineManager initialized."); } runPipeline() { return __awaiter(this, void 0, void 0, function* () { var _a; const config = ConfigStore.getInstance().getConfig(); if (!config.stages || !Array.isArray(config.stages)) { throw new Error("Invalid configuration: 'stages' must be an array."); } this.logInfo("Initializing pipeline..."); const pipeline = new Pipeline(config); try { yield pipeline.run(); this.logInfo("Pipeline execution finished successfully."); (_a = this.liveServer) === null || _a === void 0 ? void 0 : _a.reloadClients(); } catch (error) { this.logError("Error during pipeline execution.", error); throw error; } }); } restartPipeline() { if (this.isRestarting) { this.logWarn("Pipeline restart already in progress. Skipping..."); return; } this.isRestarting = true; if (this.pipelineProcess) { this.logInfo("Stopping current pipeline process..."); this.stopPipeline(); } this.logInfo("Starting pipeline..."); const scriptPath = path.resolve(process.cwd(), "dist/js/cli.js"); this.pipelineProcess = spawn("node", [scriptPath], { stdio: "inherit", }); this.attachProcessListeners(); this.isRestarting = false; } attachProcessListeners() { if (!this.pipelineProcess) return; this.pipelineProcess.on("close", (code) => { var _a; if (code !== 0) { this.logError(`Pipeline process exited with code ${code}`); } else { this.logInfo("Pipeline process exited successfully."); } (_a = this.liveServer) === null || _a === void 0 ? void 0 : _a.reloadClients(); }); this.pipelineProcess.on("error", (error) => { this.logError("Error starting pipeline process.", error); }); this.pipelineProcess.on("exit", (code, signal) => { if (signal) { this.logWarn(`Pipeline process was terminated with signal: ${signal}`); } else { this.logInfo(`Pipeline process exited with code: ${code}`); } }); } stopPipeline() { if (this.pipelineProcess) { this.logInfo("Stopping pipeline process..."); this.pipelineProcess.kill("SIGTERM"); this.pipelineProcess = null; this.logInfo("Pipeline process stopped."); } else { this.logWarn("No pipeline process is currently running."); } } isPipelineRunning() { return this.pipelineProcess !== null && !this.pipelineProcess.killed; } restartPipelineWithDelay(delay = 1000) { this.logInfo(`Delaying pipeline restart by ${delay} milliseconds...`); setTimeout(() => this.restartPipeline(), delay); } } //# sourceMappingURL=PipelineManager.js.map