aahook
Version:
A CLI tool that displays ASCII art when commands succeed or fail
87 lines ⢠3.53 kB
JavaScript
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
;