UNPKG

aahook

Version:

A CLI tool that displays ASCII art when commands succeed or fail

87 lines • 3.53 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.previewCommand = previewCommand; const aa_manager_1 = require("../aa-manager"); const github_fetcher_1 = require("../github-fetcher"); /** * Preview ASCII art (local or remote) */ async function previewCommand(artPath, options = {}) { const manager = new aa_manager_1.AAManager(); try { let content; let source; if (options.remote) { // Preview from remote repository const fetcher = new github_fetcher_1.GitHubFetcher(); // Parse art path (format: category/name) const parts = artPath.split('/'); if (parts.length !== 2) { throw new Error('Invalid art path. Use format: category/name'); } const [category, name] = parts; console.log(`\nšŸ” Fetching ${category}/${name} from repository...`); content = await fetcher.fetchArt(category, name); source = 'Remote Repository'; // Also fetch and display metadata if available try { const categoryMeta = await fetcher.fetchCategory(category); const metadata = categoryMeta.arts?.find(a => a.name === name); if (metadata) { console.log(`\nšŸ“‹ Metadata:`); console.log(` Name: ${metadata.displayName}`); console.log(` Description: ${metadata.description}`); console.log(` Author: ${metadata.author}`); if (metadata.tags.length > 0) { console.log(` Tags: ${metadata.tags.join(', ')}`); } } } catch { // Metadata is optional } } else { // Preview from local installation const art = await manager.getLocal(artPath); if (!art) { console.log(`\nāŒ ASCII art '${artPath}' not found locally.`); console.log('šŸ’” Try with --remote flag to preview from repository.'); console.log('šŸ’” Or use "npx aahook gallery" to see installed arts.\n'); return; } content = art.content; source = 'Local Installation'; } // Display the ASCII art console.log(`\nšŸŽØ Preview (${source}):`); console.log('═'.repeat(50)); console.log(content); console.log('═'.repeat(50)); if (options.remote) { console.log(`\nšŸ’” To install this art, run:`); console.log(` npx aahook install ${artPath}\n`); } else { console.log(`\nšŸ’” To use this art in hooks:`); console.log(` npx aahook config --success ${artPath}.txt`); console.log(` npx aahook config --error ${artPath}.txt\n`); } } catch (error) { if (error.message.includes('Not found')) { console.error(`\nāŒ ASCII art not found: ${artPath}`); if (options.remote) { console.error('šŸ’” Use "npx aahook browse" to see available arts in repository\n'); } else { console.error('šŸ’” Use "npx aahook gallery" to see installed arts\n'); } } else { console.error(`\nāŒ Preview failed: ${error.message}\n`); } process.exit(1); } } //# sourceMappingURL=preview.js.map