kist
Version:
Lightweight Package Pipeline Processor with Plugin Architecture
91 lines • 3.93 kB
JavaScript
import { __awaiter } from "tslib";
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.");
}
run() {
return __awaiter(this, void 0, void 0, function* () {
this.logInfo("Starting Kist workflow...");
try {
yield this.initializeActionRegistry();
const liveReloadEnabled = ConfigStore.getInstance().get("options.live.enabled");
const liveReloadServer = liveReloadEnabled
? new LiveServer()
: null;
const pipelineManager = new PipelineManager(liveReloadServer);
yield pipelineManager.runPipeline();
if (liveReloadEnabled) {
this.setupLiveReload(pipelineManager, liveReloadServer);
}
}
catch (error) {
this.handleError(error);
}
});
}
initializeActionRegistry() {
return __awaiter(this, void 0, void 0, function* () {
this.logInfo("Initializing plugin system...");
const pluginManager = PluginManager.getInstance();
yield 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));
}
handleShutdown(pipelineManager, liveReloadServer) {
return __awaiter(this, void 0, void 0, function* () {
this.logInfo("Shutdown signal received. Shutting down...");
try {
yield pipelineManager.stopPipeline();
yield 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