pub mod api;
pub mod commands;
pub mod config;
pub mod context;
pub mod engine;
pub mod error;
pub mod hooks;
pub mod loader;
pub use commands::CustomCommand;
pub use config::{HookConfig, PluginConfig};
pub use context::{BuildContext, PluginContext, TestContext};
pub use engine::{PluginSystem, SteelEngine};
pub use error::{PluginError, Result};
pub use hooks::{HookEvent, HookResult};
pub use loader::{DiscoveredPlugin, PluginPaths, discover_plugins, find_plugin};
use std::path::Path;
pub struct PluginManager {
engine: SteelEngine,
initialized: bool,
}
impl PluginManager {
pub fn new(config: PluginConfig) -> Result<Self> {
Ok(PluginManager {
engine: SteelEngine::new(config),
initialized: false,
})
}
pub fn with_defaults() -> Result<Self> {
Self::new(PluginConfig::new())
}
pub fn initialize(&mut self) -> Result<()> {
if self.initialized {
return Ok(());
}
self.engine.initialize()?;
self.initialized = true;
Ok(())
}
pub fn load_all(&mut self, project_root: &Path) -> Result<()> {
self.ensure_initialized()?;
let plugins = discover_plugins(self.engine.config(), project_root)?;
for plugin in plugins {
if let Err(e) = self.engine.load_plugin(&plugin.path) {
tracing::warn!("Failed to load plugin {}: {}", plugin.name, e);
}
}
Ok(())
}
pub fn load_plugin(&mut self, path: &Path) -> Result<()> {
self.ensure_initialized()?;
self.engine.load_plugin(path)
}
pub fn run_hook(&mut self, event: HookEvent, ctx: &PluginContext) -> Result<HookResult> {
self.ensure_initialized()?;
self.engine.run_hook(event, ctx)
}
pub fn run_command(&mut self, name: &str, args: &[String]) -> Result<i32> {
self.ensure_initialized()?;
self.engine.run_command(name, args)
}
pub fn commands(&self) -> &std::collections::HashMap<String, CustomCommand> {
self.engine.commands()
}
pub fn config(&self) -> &PluginConfig {
self.engine.config()
}
pub fn has_command(&self, name: &str) -> bool {
self.engine.commands().contains_key(name)
}
fn ensure_initialized(&mut self) -> Result<()> {
if !self.initialized {
self.initialize()?;
}
Ok(())
}
}
pub fn plugins_enabled(config: &PluginConfig) -> bool {
config.enabled
}
pub fn test_context(project_root: impl Into<std::path::PathBuf>, name: &str) -> PluginContext {
PluginContext::new(project_root.into(), name.to_string())
}