UNPKG

docker-pilot

Version:

A powerful, scalable Docker CLI library for managing containerized applications of any size

133 lines 4.04 kB
"use strict"; /** * Base Plugin class for Docker Pilot * Provides common functionality for all plugins */ Object.defineProperty(exports, "__esModule", { value: true }); exports.BasePlugin = void 0; const Logger_1 = require("../utils/Logger"); const i18n_1 = require("../utils/i18n"); class BasePlugin { constructor(metadata, hooks, commands) { this.metadata = metadata; this.context = null; this.logger = new Logger_1.Logger(); this.i18n = new i18n_1.I18n(); if (hooks) this.hooks = hooks; if (commands) this.commands = commands; } /** * Initialize the plugin */ async initialize(context) { this.context = context; // Configure i18n based on context config if (context.config?.language) { this.i18n.setLanguage(context.config.language); } this.logger.debug(this.i18n.t('plugin.initializing', { name: this.metadata.name })); await this.onInitialize(); } /** * Cleanup the plugin */ async cleanup() { this.logger.debug(this.i18n.t('plugin.cleanup', { name: this.metadata.name })); await this.onCleanup(); this.context = null; } /** * Update plugin configuration */ async updateConfig(config) { await this.onConfigUpdate(config); } /** * Update language for the plugin */ updateLanguage(language) { this.i18n.setLanguage(language); } /** * Check if plugin is compatible with Docker Pilot version */ isCompatible(_dockerPilotVersion) { // Simple version compatibility check // In a real implementation, you'd use semver for proper version comparison return true; } /** * Get plugin status */ getStatus() { return this.context ? 'active' : 'inactive'; } /** * Called when plugin is initialized * Override this method in your plugin */ async onInitialize() { // Override in subclass } /** * Called when plugin is being cleaned up * Override this method in your plugin */ async onCleanup() { // Override in subclass } /** * Called when plugin configuration is updated * Override this method in your plugin */ async onConfigUpdate(_config) { // Override in subclass } /** * Helper method to emit events */ emit(event, data) { // In a real implementation, this would emit events to the Docker Pilot event system this.logger.debug(`Plugin ${this.metadata.name} emitted event: ${event}`, data); } /** * Helper method to execute Docker commands */ async executeCommand(command, args = []) { // In a real implementation, this would use the Docker Pilot command system this.logger.debug(`Plugin ${this.metadata.name} executing command: ${command} ${args.join(' ')}`); return { success: true, output: '' }; } /** * Helper method to get service status */ async getServiceStatus(serviceName) { // In a real implementation, this would use the Docker Pilot service manager this.logger.debug(`Plugin ${this.metadata.name} getting service status for: ${serviceName || 'all'}`); return []; } /** * Helper method to log messages */ log(level, message, data) { const prefixedMessage = `[${this.metadata.name}] ${message}`; switch (level) { case 'debug': this.logger.debug(prefixedMessage, data); break; case 'info': this.logger.info(prefixedMessage, data); break; case 'warn': this.logger.warn(prefixedMessage, data); break; case 'error': this.logger.error(prefixedMessage, data); break; } } } exports.BasePlugin = BasePlugin; //# sourceMappingURL=BasePlugin.js.map