UNPKG

kist

Version:

Lightweight Package Pipeline Processor with Plugin Architecture

84 lines 3.51 kB
import { AbstractProcess } from "./core/abstract/AbstractProcess.js"; import { ConfigStore } from "./core/config/ConfigStore.js"; import { ActionRegistry } from "./core/pipeline/ActionRegistry.js"; import { PipelineManager } from "./core/pipeline/PipelineManager.js"; import { PluginManager } from "./core/plugin/PluginManager.js"; import { LiveServer } from "./live/LiveServer.js"; import { LiveWatcher } from "./live/LiveWatcher.js"; export class Kist extends AbstractProcess { constructor() { super(); this.logDebug("Kist initialized."); } async run() { this.logInfo("Starting Kist workflow..."); try { await this.initializeActionRegistry(); const liveReloadEnabled = ConfigStore.getInstance().get("options.live.enabled"); const liveReloadServer = liveReloadEnabled ? new LiveServer() : null; const pipelineManager = new PipelineManager(liveReloadServer); await pipelineManager.runPipeline(); if (liveReloadEnabled) { this.setupLiveReload(pipelineManager, liveReloadServer); } } catch (error) { this.handleError(error); } } async initializeActionRegistry() { this.logInfo("Initializing plugin system..."); const pluginManager = PluginManager.getInstance(); await pluginManager.discoverPlugins({ pluginPrefixes: ["@getkist/action-", "kist-plugin-"], }); const plugins = pluginManager.getLoadedPlugins(); if (plugins.length > 0) { this.logInfo(`Loaded ${plugins.length} plugin(s):`); plugins.forEach((plugin) => { this.logInfo(` - ${plugin.name} v${plugin.version} (${plugin.actions.length} actions)`); }); } else { this.logDebug("No external plugins found."); } this.logInfo("Initializing ActionRegistry..."); ActionRegistry.initialize(); this.logInfo("ActionRegistry initialized successfully."); } setupLiveReload(pipelineManager, liveReloadServer) { this.logInfo("Enabling live reload functionality..."); new LiveWatcher((filePath) => { this.logInfo(`Detected change in: ${filePath}. Restarting pipeline...`); pipelineManager.restartPipelineWithDelay(500); }); pipelineManager.restartPipeline(); this.registerShutdownHandlers(pipelineManager, liveReloadServer); } registerShutdownHandlers(pipelineManager, liveReloadServer) { process.on("SIGINT", () => this.handleShutdown(pipelineManager, liveReloadServer)); process.on("SIGTERM", () => this.handleShutdown(pipelineManager, liveReloadServer)); } async handleShutdown(pipelineManager, liveReloadServer) { this.logInfo("Shutdown signal received. Shutting down..."); try { await pipelineManager.stopPipeline(); await liveReloadServer.shutdown(); this.logInfo("Shutdown completed successfully."); } catch (error) { this.logError("Error during shutdown.", error); } finally { process.exit(0); } } handleError(error) { const errorMessage = error instanceof Error ? error.message : String(error); this.logError(`An error occurred: ${errorMessage}`, error); process.exit(1); } } //# sourceMappingURL=kist.js.map