@re-shell/cli
Version:
Full-stack development platform uniting microservices and microfrontends. Build complete applications with .NET (ASP.NET Core Web API, Minimal API), Java (Spring Boot, Quarkus, Micronaut, Vert.x), Rust (Actix-Web, Warp, Rocket, Axum), Python (FastAPI, Dja
653 lines (652 loc) ⢠30.2 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.managePlugins = managePlugins;
exports.discoverPlugins = discoverPlugins;
exports.installPlugin = installPlugin;
exports.uninstallPlugin = uninstallPlugin;
exports.showPluginInfo = showPluginInfo;
exports.enablePlugin = enablePlugin;
exports.disablePlugin = disablePlugin;
exports.updatePlugins = updatePlugins;
exports.validatePlugin = validatePlugin;
exports.clearPluginCache = clearPluginCache;
exports.showPluginStats = showPluginStats;
exports.reloadPlugin = reloadPlugin;
exports.showPluginHooks = showPluginHooks;
exports.executeHook = executeHook;
exports.listHookTypes = listHookTypes;
const chalk_1 = __importDefault(require("chalk"));
const spinner_1 = require("../utils/spinner");
const error_handler_1 = require("../utils/error-handler");
const plugin_system_1 = require("../utils/plugin-system");
const plugin_lifecycle_1 = require("../utils/plugin-lifecycle");
const plugin_hooks_1 = require("../utils/plugin-hooks");
// Main plugin management function
async function managePlugins(options = {}) {
const { verbose = false, json = false } = options;
try {
const registry = (0, plugin_system_1.createPluginRegistry)();
const spinner = (0, spinner_1.createSpinner)('Initializing plugin registry...');
spinner.start();
await registry.initialize();
spinner.stop();
const plugins = registry.getManagedPlugins();
if (json) {
console.log(JSON.stringify(plugins.map(p => ({
name: p.manifest.name,
version: p.manifest.version,
description: p.manifest.description,
path: p.pluginPath,
isLoaded: p.isLoaded,
isActive: p.isActive,
usageCount: p.usageCount,
state: p.state
})), null, 2));
return;
}
if (plugins.length === 0) {
console.log(chalk_1.default.yellow('No plugins found.'));
console.log(chalk_1.default.gray('Run "re-shell plugin discover" to search for available plugins.'));
return;
}
console.log(chalk_1.default.cyan(`\nš Installed Plugins (${plugins.length})\n`));
displayPluginList(plugins, verbose);
}
catch (error) {
throw new error_handler_1.ValidationError(`Plugin management failed: ${error instanceof Error ? error.message : String(error)}`);
}
}
// Discover available plugins
async function discoverPlugins(options = {}) {
const { verbose = false, json = false, source, includeDisabled = false, includeDev = true, timeout = 10000 } = options;
try {
const registry = (0, plugin_system_1.createPluginRegistry)();
const discoveryOptions = {
sources: source ? [source] : ['local', 'npm', 'builtin'],
includeDisabled,
includeDev,
timeout,
useCache: false // Always fresh discovery
};
const spinner = (0, spinner_1.createSpinner)('Discovering plugins...');
spinner.start();
const result = await registry.discoverPlugins(discoveryOptions);
spinner.stop();
if (json) {
console.log(JSON.stringify(result, null, 2));
return;
}
console.log(chalk_1.default.cyan(`\nš Plugin Discovery Results\n`));
if (result.found.length > 0) {
console.log(chalk_1.default.green(`Found ${result.found.length} plugins:\n`));
displayDiscoveredPluginList(result.found, verbose);
}
else {
console.log(chalk_1.default.yellow('No plugins found.'));
}
if (result.errors.length > 0) {
console.log(chalk_1.default.red(`\nā Errors (${result.errors.length}):\n`));
result.errors.forEach((error, index) => {
console.log(`${index + 1}. ${chalk_1.default.red(error.path)}: ${error.error.message}`);
});
}
if (result.skipped.length > 0 && verbose) {
console.log(chalk_1.default.yellow(`\nāļø Skipped (${result.skipped.length}):\n`));
result.skipped.forEach((skipped, index) => {
console.log(`${index + 1}. ${chalk_1.default.gray(skipped.path)}: ${skipped.reason}`);
});
}
}
catch (error) {
throw new error_handler_1.ValidationError(`Plugin discovery failed: ${error instanceof Error ? error.message : String(error)}`);
}
}
// Install a plugin
async function installPlugin(pluginIdentifier, options = {}) {
const { verbose = false, global = false, force = false } = options;
try {
const spinner = (0, spinner_1.createSpinner)(`Installing plugin ${pluginIdentifier}...`);
spinner.start();
// TODO: Implement plugin installation logic
// This would involve:
// 1. Resolving plugin identifier (npm package, git repo, local path)
// 2. Downloading/copying plugin files
// 3. Validating plugin manifest
// 4. Installing dependencies
// 5. Registering plugin
await new Promise(resolve => setTimeout(resolve, 2000)); // Simulate installation
spinner.succeed(chalk_1.default.green(`Plugin ${pluginIdentifier} installed successfully!`));
if (verbose) {
console.log(chalk_1.default.gray(`Installation location: ${global ? 'global' : 'local'}`));
}
}
catch (error) {
throw new error_handler_1.ValidationError(`Plugin installation failed: ${error instanceof Error ? error.message : String(error)}`);
}
}
// Uninstall a plugin
async function uninstallPlugin(pluginName, options = {}) {
const { verbose = false, force = false } = options;
try {
const registry = (0, plugin_system_1.createPluginRegistry)();
await registry.initialize();
const plugin = registry.getManagedPlugin(pluginName);
if (!plugin) {
throw new error_handler_1.ValidationError(`Plugin '${pluginName}' is not installed`);
}
if (!force) {
// TODO: Add confirmation prompt
console.log(chalk_1.default.yellow(`Are you sure you want to uninstall '${pluginName}'?`));
}
const spinner = (0, spinner_1.createSpinner)(`Uninstalling plugin ${pluginName}...`);
spinner.start();
// Unload the plugin (which includes deactivation)
await registry.unloadPlugin(pluginName);
// Unregister from registry
const success = await registry.unregisterPlugin(pluginName);
if (!success) {
throw new error_handler_1.ValidationError(`Failed to unregister plugin '${pluginName}'`);
}
// TODO: Remove plugin files and dependencies
await new Promise(resolve => setTimeout(resolve, 1000)); // Simulate uninstallation
spinner.succeed(chalk_1.default.green(`Plugin ${pluginName} uninstalled successfully!`));
}
catch (error) {
throw new error_handler_1.ValidationError(`Plugin uninstallation failed: ${error instanceof Error ? error.message : String(error)}`);
}
}
// Show plugin information
async function showPluginInfo(pluginName, options = {}) {
const { verbose = false, json = false } = options;
try {
const registry = (0, plugin_system_1.createPluginRegistry)();
await registry.initialize();
const plugin = registry.getManagedPlugin(pluginName);
if (!plugin) {
throw new error_handler_1.ValidationError(`Plugin '${pluginName}' not found`);
}
if (json) {
console.log(JSON.stringify({
manifest: plugin.manifest,
path: plugin.pluginPath,
isLoaded: plugin.isLoaded,
isActive: plugin.isActive,
usageCount: plugin.usageCount,
lastUsed: plugin.lastUsed,
state: plugin.state,
dependencies: plugin.dependencies,
dependents: plugin.dependents,
performance: plugin.performance,
errors: plugin.errors,
stateHistory: plugin.stateHistory
}, null, 2));
return;
}
console.log(chalk_1.default.cyan(`\nš¦ ${plugin.manifest.name} v${plugin.manifest.version}\n`));
displayPluginDetails(plugin, verbose);
}
catch (error) {
throw new error_handler_1.ValidationError(`Failed to show plugin info: ${error instanceof Error ? error.message : String(error)}`);
}
}
// Enable a plugin
async function enablePlugin(pluginName, options = {}) {
const { verbose = false } = options;
try {
const registry = (0, plugin_system_1.createPluginRegistry)();
await registry.initialize();
const plugin = registry.getManagedPlugin(pluginName);
if (!plugin) {
throw new error_handler_1.ValidationError(`Plugin '${pluginName}' not found`);
}
const spinner = (0, spinner_1.createSpinner)(`Enabling plugin ${pluginName}...`);
spinner.start();
// Load plugin if not loaded
if (plugin.state === plugin_lifecycle_1.PluginState.UNLOADED) {
await registry.loadPlugin(pluginName);
}
// Initialize plugin if not initialized
if (plugin.state === plugin_lifecycle_1.PluginState.LOADED) {
await registry.initializePlugin(pluginName);
}
// Activate plugin if not active
if (plugin.state === plugin_lifecycle_1.PluginState.INITIALIZED) {
await registry.activatePlugin(pluginName);
}
spinner.succeed(chalk_1.default.green(`Plugin ${pluginName} enabled successfully!`));
if (verbose) {
console.log(chalk_1.default.gray(`Plugin state: ${plugin.state}`));
console.log(chalk_1.default.gray(`Load time: ${plugin.performance.loadDuration}ms`));
console.log(chalk_1.default.gray(`Init time: ${plugin.performance.initDuration}ms`));
console.log(chalk_1.default.gray(`Activation time: ${plugin.performance.activationDuration}ms`));
}
}
catch (error) {
throw new error_handler_1.ValidationError(`Failed to enable plugin: ${error instanceof Error ? error.message : String(error)}`);
}
}
// Disable a plugin
async function disablePlugin(pluginName, options = {}) {
const { verbose = false } = options;
try {
const registry = (0, plugin_system_1.createPluginRegistry)();
await registry.initialize();
const plugin = registry.getManagedPlugin(pluginName);
if (!plugin) {
throw new error_handler_1.ValidationError(`Plugin '${pluginName}' not found`);
}
if (plugin.state !== plugin_lifecycle_1.PluginState.ACTIVE) {
console.log(chalk_1.default.yellow(`Plugin ${pluginName} is not active (current state: ${plugin.state})`));
return;
}
const spinner = (0, spinner_1.createSpinner)(`Disabling plugin ${pluginName}...`);
spinner.start();
await registry.deactivatePlugin(pluginName);
spinner.succeed(chalk_1.default.yellow(`Plugin ${pluginName} disabled successfully!`));
if (verbose) {
console.log(chalk_1.default.gray(`Plugin state: ${plugin.state}`));
console.log(chalk_1.default.gray(`Dependencies: ${plugin.dependents.join(', ') || 'none'}`));
}
}
catch (error) {
throw new error_handler_1.ValidationError(`Failed to disable plugin: ${error instanceof Error ? error.message : String(error)}`);
}
}
// Update plugins
async function updatePlugins(options = {}) {
const { verbose = false } = options;
try {
const registry = (0, plugin_system_1.createPluginRegistry)();
await registry.initialize();
const plugins = registry.getPlugins();
if (plugins.length === 0) {
console.log(chalk_1.default.yellow('No plugins to update.'));
return;
}
const spinner = (0, spinner_1.createSpinner)(`Checking for plugin updates...`);
spinner.start();
// TODO: Implement update checking and installation
await new Promise(resolve => setTimeout(resolve, 2000)); // Simulate update check
spinner.succeed(chalk_1.default.green('All plugins are up to date!'));
}
catch (error) {
throw new error_handler_1.ValidationError(`Plugin update failed: ${error instanceof Error ? error.message : String(error)}`);
}
}
// Display discovered plugin list (without lifecycle info)
function displayDiscoveredPluginList(plugins, verbose) {
plugins.forEach((plugin, index) => {
const status = plugin.isActive ? chalk_1.default.green('ā') : plugin.isLoaded ? chalk_1.default.yellow('ā') : chalk_1.default.gray('ā');
const statusText = plugin.isActive ? 'active' : plugin.isLoaded ? 'loaded' : 'inactive';
console.log(`${status} ${chalk_1.default.white(plugin.manifest.name)} ${chalk_1.default.gray(`v${plugin.manifest.version}`)}`);
console.log(` ${chalk_1.default.gray(plugin.manifest.description)}`);
if (verbose) {
console.log(` ${chalk_1.default.gray(`Path: ${plugin.pluginPath}`)}`);
console.log(` ${chalk_1.default.gray(`Status: ${statusText}`)}`);
if (plugin.usageCount > 0) {
console.log(` ${chalk_1.default.gray(`Usage: ${plugin.usageCount} times`)}`);
}
}
if (index < plugins.length - 1) {
console.log('');
}
});
}
// Display plugin list with lifecycle info
function displayPluginList(plugins, verbose) {
plugins.forEach((plugin, index) => {
const status = plugin.state === plugin_lifecycle_1.PluginState.ACTIVE ? chalk_1.default.green('ā') :
plugin.state === plugin_lifecycle_1.PluginState.LOADED || plugin.state === plugin_lifecycle_1.PluginState.INITIALIZED ? chalk_1.default.yellow('ā') :
chalk_1.default.gray('ā');
const statusText = plugin.state;
console.log(`${status} ${chalk_1.default.white(plugin.manifest.name)} ${chalk_1.default.gray(`v${plugin.manifest.version}`)}`);
console.log(` ${chalk_1.default.gray(plugin.manifest.description)}`);
if (verbose) {
console.log(` ${chalk_1.default.gray(`Path: ${plugin.pluginPath}`)}`);
console.log(` ${chalk_1.default.gray(`Status: ${statusText}`)}`);
if (plugin.usageCount > 0) {
console.log(` ${chalk_1.default.gray(`Usage: ${plugin.usageCount} times`)}`);
}
}
if (index < plugins.length - 1) {
console.log('');
}
});
}
// Display detailed plugin information
function displayPluginDetails(plugin, verbose) {
const manifest = plugin.manifest;
console.log(chalk_1.default.yellow('Description:'));
console.log(` ${manifest.description}\n`);
if (manifest.author) {
console.log(chalk_1.default.yellow('Author:'));
console.log(` ${manifest.author}\n`);
}
console.log(chalk_1.default.yellow('Version:'));
console.log(` ${manifest.version}\n`);
if (manifest.license) {
console.log(chalk_1.default.yellow('License:'));
console.log(` ${manifest.license}\n`);
}
if (manifest.homepage) {
console.log(chalk_1.default.yellow('Homepage:'));
console.log(` ${manifest.homepage}\n`);
}
if (manifest.keywords && manifest.keywords.length > 0) {
console.log(chalk_1.default.yellow('Keywords:'));
console.log(` ${manifest.keywords.join(', ')}\n`);
}
console.log(chalk_1.default.yellow('Installation:'));
console.log(` Path: ${plugin.pluginPath}`);
console.log(` State: ${plugin.state}`);
console.log(` Status: ${plugin.isActive ? 'Active' : plugin.isLoaded ? 'Loaded' : 'Inactive'}`);
if (plugin.usageCount > 0) {
console.log(` Usage Count: ${plugin.usageCount}`);
}
if (plugin.lastUsed) {
console.log(` Last Used: ${new Date(plugin.lastUsed).toLocaleString()}`);
}
console.log(`\n${chalk_1.default.yellow('Lifecycle:')}`);
console.log(` Load Time: ${plugin.performance.loadDuration}ms`);
console.log(` Init Time: ${plugin.performance.initDuration}ms`);
console.log(` Activation Time: ${plugin.performance.activationDuration}ms`);
if (plugin.dependencies.length > 0) {
console.log(`\n${chalk_1.default.yellow('Dependencies:')}`);
plugin.dependencies.forEach(dep => {
const status = dep.resolved ? chalk_1.default.green('ā') : chalk_1.default.red('ā');
console.log(` ${status} ${dep.name} (${dep.version}) ${dep.required ? '' : '(optional)'}`);
});
}
if (plugin.dependents.length > 0) {
console.log(`\n${chalk_1.default.yellow('Dependents:')}`);
plugin.dependents.forEach(dep => {
console.log(` - ${dep}`);
});
}
if (plugin.errors.length > 0) {
console.log(`\n${chalk_1.default.red('Recent Errors:')}`);
plugin.errors.slice(-3).forEach((error, index) => {
console.log(` ${index + 1}. [${error.stage}] ${error.error.message}`);
console.log(` ${chalk_1.default.gray(new Date(error.timestamp).toLocaleString())}`);
});
}
if (verbose) {
console.log(`\n${chalk_1.default.yellow('Manifest:')}`);
console.log(` Main: ${manifest.main}`);
if (manifest.engines) {
console.log(` Engines: ${JSON.stringify(manifest.engines)}`);
}
if (manifest.dependencies) {
console.log(` Dependencies: ${Object.keys(manifest.dependencies).length}`);
}
if (manifest.reshell) {
console.log(` Re-Shell Config: ${JSON.stringify(manifest.reshell, null, 2)}`);
}
if (plugin.loadError) {
console.log(`\n${chalk_1.default.red('Load Error:')}`);
console.log(` ${plugin.loadError.message}`);
}
if (plugin.activationError) {
console.log(`\n${chalk_1.default.red('Activation Error:')}`);
console.log(` ${plugin.activationError.message}`);
}
}
}
// Validate plugin compatibility
async function validatePlugin(pluginPath, options = {}) {
const { verbose = false, json = false } = options;
try {
const spinner = (0, spinner_1.createSpinner)('Validating plugin...');
spinner.start();
// TODO: Implement comprehensive plugin validation
// This would check:
// 1. Manifest validity
// 2. Code structure
// 3. Dependencies compatibility
// 4. Security scanning
// 5. Performance analysis
await new Promise(resolve => setTimeout(resolve, 1500)); // Simulate validation
spinner.succeed(chalk_1.default.green('Plugin validation passed!'));
if (verbose) {
console.log(chalk_1.default.gray('All checks completed successfully.'));
}
}
catch (error) {
throw new error_handler_1.ValidationError(`Plugin validation failed: ${error instanceof Error ? error.message : String(error)}`);
}
}
// Clear plugin cache
async function clearPluginCache(options = {}) {
const { verbose = false } = options;
try {
const registry = (0, plugin_system_1.createPluginRegistry)();
registry.clearCache();
console.log(chalk_1.default.green('Plugin discovery cache cleared!'));
}
catch (error) {
throw new error_handler_1.ValidationError(`Failed to clear plugin cache: ${error instanceof Error ? error.message : String(error)}`);
}
}
// Show plugin lifecycle statistics
async function showPluginStats(options = {}) {
const { verbose = false, json = false } = options;
try {
const registry = (0, plugin_system_1.createPluginRegistry)();
await registry.initialize();
const stats = registry.getLifecycleStats();
if (json) {
console.log(JSON.stringify(stats, null, 2));
return;
}
console.log(chalk_1.default.cyan('\nš Plugin Lifecycle Statistics\n'));
console.log(chalk_1.default.yellow('Overview:'));
console.log(` Total Plugins: ${stats.total}`);
console.log(` Total Errors: ${stats.totalErrors}`);
console.log(chalk_1.default.yellow('\nBy State:'));
Object.entries(stats.byState).forEach(([state, count]) => {
const stateColor = state === 'active' ? chalk_1.default.green :
state === 'loaded' || state === 'initialized' ? chalk_1.default.yellow :
state === 'error' ? chalk_1.default.red : chalk_1.default.gray;
console.log(` ${stateColor(state)}: ${count}`);
});
console.log(chalk_1.default.yellow('\nPerformance:'));
console.log(` Average Load Time: ${Math.round(stats.avgLoadTime)}ms`);
console.log(` Average Init Time: ${Math.round(stats.avgInitTime)}ms`);
console.log(` Average Activation Time: ${Math.round(stats.avgActivationTime)}ms`);
if (verbose) {
const plugins = registry.getManagedPlugins();
const errorPlugins = plugins.filter(p => p.errors.length > 0);
if (errorPlugins.length > 0) {
console.log(chalk_1.default.red('\nPlugins with Errors:'));
errorPlugins.forEach(plugin => {
console.log(` ${plugin.manifest.name}: ${plugin.errors.length} errors`);
});
}
}
}
catch (error) {
throw new error_handler_1.ValidationError(`Failed to show plugin statistics: ${error instanceof Error ? error.message : String(error)}`);
}
}
// Reload a plugin
async function reloadPlugin(pluginName, options = {}) {
const { verbose = false } = options;
try {
const registry = (0, plugin_system_1.createPluginRegistry)();
await registry.initialize();
const plugin = registry.getManagedPlugin(pluginName);
if (!plugin) {
throw new error_handler_1.ValidationError(`Plugin '${pluginName}' not found`);
}
const spinner = (0, spinner_1.createSpinner)(`Reloading plugin ${pluginName}...`);
spinner.start();
await registry.reloadPlugin(pluginName);
spinner.succeed(chalk_1.default.green(`Plugin ${pluginName} reloaded successfully!`));
if (verbose) {
const reloadedPlugin = registry.getManagedPlugin(pluginName);
if (reloadedPlugin) {
console.log(chalk_1.default.gray(`Plugin state: ${reloadedPlugin.state}`));
console.log(chalk_1.default.gray(`Load time: ${reloadedPlugin.performance.loadDuration}ms`));
}
}
}
catch (error) {
throw new error_handler_1.ValidationError(`Failed to reload plugin: ${error instanceof Error ? error.message : String(error)}`);
}
}
// Show plugin hooks
async function showPluginHooks(pluginName, options = {}) {
const { verbose = false, json = false } = options;
try {
const registry = (0, plugin_system_1.createPluginRegistry)();
await registry.initialize();
const hookStats = registry.getHookStats();
if (json) {
if (pluginName) {
const hookSystem = registry.getHookSystem();
const pluginHooks = hookSystem.getPluginHooks(pluginName);
console.log(JSON.stringify(pluginHooks, null, 2));
}
else {
console.log(JSON.stringify(hookStats, null, 2));
}
return;
}
console.log(chalk_1.default.cyan('\nšŖ Plugin Hooks Overview\n'));
if (pluginName) {
const hookSystem = registry.getHookSystem();
const pluginHooks = hookSystem.getPluginHooks(pluginName);
if (pluginHooks.length === 0) {
console.log(chalk_1.default.yellow(`No hooks registered for plugin '${pluginName}'`));
return;
}
console.log(chalk_1.default.green(`Hooks for plugin '${pluginName}' (${pluginHooks.length}):\n`));
pluginHooks.forEach((hook, index) => {
console.log(`${index + 1}. ${chalk_1.default.white(hook.id)}`);
console.log(` Type: ${chalk_1.default.cyan(hook.hookType || 'unknown')}`);
console.log(` Priority: ${hook.priority}`);
if (hook.description) {
console.log(` Description: ${chalk_1.default.gray(hook.description)}`);
}
if (hook.once) {
console.log(` ${chalk_1.default.yellow('(one-time)')}`);
}
if (index < pluginHooks.length - 1) {
console.log('');
}
});
}
else {
console.log(chalk_1.default.yellow('Overview:'));
console.log(` Total Hooks: ${hookStats.totalHooks}`);
console.log(` Active Middleware: ${hookStats.middleware.length}`);
console.log(chalk_1.default.yellow('\nBy Hook Type:'));
Object.entries(hookStats.hooksByType).forEach(([type, count]) => {
if (count > 0) {
console.log(` ${chalk_1.default.cyan(type)}: ${count}`);
}
});
console.log(chalk_1.default.yellow('\nBy Plugin:'));
Object.entries(hookStats.hooksByPlugin).forEach(([plugin, count]) => {
console.log(` ${chalk_1.default.white(plugin)}: ${count} hooks`);
});
if (verbose && Object.keys(hookStats.executionStats).length > 0) {
console.log(chalk_1.default.yellow('\nExecution Time (total ms):'));
Object.entries(hookStats.executionStats).forEach(([plugin, time]) => {
console.log(` ${plugin}: ${time}ms`);
});
}
}
}
catch (error) {
throw new error_handler_1.ValidationError(`Failed to show plugin hooks: ${error instanceof Error ? error.message : String(error)}`);
}
}
// Execute a hook manually
async function executeHook(hookType, data = '{}', options = {}) {
const { verbose = false, json = false } = options;
try {
const registry = (0, plugin_system_1.createPluginRegistry)();
await registry.initialize();
let hookData;
try {
hookData = JSON.parse(data);
}
catch (error) {
throw new error_handler_1.ValidationError('Hook data must be valid JSON');
}
const spinner = (0, spinner_1.createSpinner)(`Executing hook ${hookType}...`);
spinner.start();
const result = await registry.executeHooks(hookType, hookData);
spinner.stop();
if (json) {
console.log(JSON.stringify(result, null, 2));
return;
}
console.log(chalk_1.default.cyan(`\nšŖ Hook Execution Result\n`));
console.log(chalk_1.default.yellow('Execution:'));
console.log(` Hook Type: ${chalk_1.default.cyan(hookType)}`);
console.log(` Success: ${result.success ? chalk_1.default.green('ā') : chalk_1.default.red('ā')}`);
console.log(` Execution Time: ${result.executionTime}ms`);
console.log(` Results: ${result.results.length}`);
console.log(` Errors: ${result.errors.length}`);
if (result.aborted) {
console.log(` ${chalk_1.default.yellow('ā ļø Execution was aborted')}`);
}
if (result.results.length > 0 && verbose) {
console.log(chalk_1.default.yellow('\nResults:'));
result.results.forEach((res, index) => {
console.log(` ${index + 1}. ${chalk_1.default.white(res.pluginName)}: ${res.executionTime}ms`);
if (res.result !== undefined) {
console.log(` Result: ${JSON.stringify(res.result)}`);
}
});
}
if (result.errors.length > 0) {
console.log(chalk_1.default.red('\nErrors:'));
result.errors.forEach((err, index) => {
console.log(` ${index + 1}. ${chalk_1.default.red(err.pluginName)}: ${err.error.message}`);
});
}
}
catch (error) {
throw new error_handler_1.ValidationError(`Failed to execute hook: ${error instanceof Error ? error.message : String(error)}`);
}
}
// List available hook types
async function listHookTypes(options = {}) {
const { json = false } = options;
try {
const hookTypes = Object.values(plugin_hooks_1.HookType);
if (json) {
console.log(JSON.stringify(hookTypes, null, 2));
return;
}
console.log(chalk_1.default.cyan('\nšŖ Available Hook Types\n'));
const categories = {
'CLI Lifecycle': hookTypes.filter(t => t.startsWith('cli:')),
'Commands': hookTypes.filter(t => t.startsWith('command:')),
'Workspace': hookTypes.filter(t => t.startsWith('workspace:')),
'Files': hookTypes.filter(t => t.startsWith('file:')),
'Build': hookTypes.filter(t => t.startsWith('build:')),
'Plugins': hookTypes.filter(t => t.startsWith('plugin:')),
'Configuration': hookTypes.filter(t => t.startsWith('config:')),
'Other': hookTypes.filter(t => !t.includes(':'))
};
Object.entries(categories).forEach(([category, types]) => {
if (types.length > 0) {
console.log(chalk_1.default.yellow(`${category}:`));
types.forEach(type => {
console.log(` ${chalk_1.default.cyan(type)}`);
});
console.log('');
}
});
}
catch (error) {
throw new error_handler_1.ValidationError(`Failed to list hook types: ${error instanceof Error ? error.message : String(error)}`);
}
}