UNPKG

doclyft

Version:

CLI for DocLyft - Interactive documentation generator with hosted documentation support

214 lines (213 loc) 6.33 kB
"use strict"; /** * Common UI patterns and utilities to eliminate repetitive code * Consolidates frequently used UI elements across the CLI */ Object.defineProperty(exports, "__esModule", { value: true }); exports.initCommand = initCommand; exports.showWorkingDirectoryConfirmation = showWorkingDirectoryConfirmation; exports.showChangeDirectoryInstructions = showChangeDirectoryInstructions; exports.showNextSteps = showNextSteps; exports.showGitHubTokenInstructions = showGitHubTokenInstructions; exports.showAuthenticationError = showAuthenticationError; exports.showSuccessMessage = showSuccessMessage; exports.showErrorMessage = showErrorMessage; exports.showNoItemsFound = showNoItemsFound; const visual_1 = require("./visual"); const banner_1 = require("./banner"); /** * Standard command initialization - shows banner and header if needed */ function initCommand(title, options = {}) { if (options.showBanner !== false) { (0, banner_1.showCompactBanner)(); } if (title) { console.log('\n'); console.log((0, visual_1.createHeader)(title, { style: 'banner', color: 'blue', width: options.width || 70 })); } } /** * Standard working directory confirmation box */ function showWorkingDirectoryConfirmation(context = 'analysis') { const currentDir = process.cwd(); const actions = { analysis: 'analyze this repository', generation: 'generate documentation', push: 'push documentation' }; console.log(''); console.log((0, visual_1.createBox)([ '📋 Working Directory Confirmation', '', `Current directory: ${currentDir}`, `Action: ${actions[context]}`, '', '✅ Press Enter to continue, or Ctrl+C to cancel' ], { title: '📍 Location Check', style: 'single', color: 'blue', padding: 1, width: 70 })); } /** * Standard "change directory" instructions */ function showChangeDirectoryInstructions() { console.log(''); console.log((0, visual_1.createBox)([ '📍 Change Directory Instructions:', '', '1. Open a new terminal window', '2. Navigate to your project: cd /path/to/your/project', '3. Re-run this command from the project root', '', '💡 The project root should contain files like package.json, README.md, etc.' ], { title: '🔄 Directory Change Required', style: 'single', color: 'yellow', padding: 1, width: 70 })); } /** * Standard "next steps" box with dynamic content */ function showNextSteps(steps, title = '🚀 Next Steps', color = 'green') { const content = [title, '', ...steps]; console.log((0, visual_1.createBox)(content, { title: '📋 What\'s Next', style: 'single', color, padding: 1, width: 65 })); } /** * Standard GitHub token error/setup instructions */ function showGitHubTokenInstructions(context = 'missing') { const messages = { missing: { title: '🔑 GitHub Token Required', description: 'A GitHub personal access token is required for repository access' }, invalid: { title: '🔑 GitHub Token Invalid', description: 'Your GitHub token appears to be invalid or expired' }, update: { title: '🔧 Token Update Required', description: 'Please update your GitHub token' } }; const { title, description } = messages[context]; console.log((0, visual_1.createBox)([ title, '', description, '', '📋 Steps to fix:', '1. Generate token: https://github.com/settings/tokens', '2. Set token: doclyft github-token', '3. Re-run this command', '', '💡 Token needs "repo" scope for private repositories' ], { title: '🛠️ Setup Required', style: 'single', color: 'yellow', padding: 1, width: 70 })); } /** * Standard authentication error display */ function showAuthenticationError(action = 'continue') { console.log((0, visual_1.createBox)([ '🔐 Authentication Required', '', `You need to be logged in to ${action}`, '', '📋 To authenticate:', '• Run: doclyft login', '• Follow the prompts to enter your API token', '• Get your token from: https://doclyft.com/dashboard/api-keys', '', '💡 Your session will be saved securely' ], { title: '🚪 Login Required', style: 'single', color: 'yellow', padding: 1, width: 70 })); } /** * Standard success message with optional next steps */ function showSuccessMessage(title, details, nextSteps) { const content = [ `✅ ${title}`, '', ...details ]; if (nextSteps && nextSteps.length > 0) { content.push('', '🚀 Next Steps:', ...nextSteps.map(step => `• ${step}`)); } console.log((0, visual_1.createBox)(content, { title: '🎉 Success', style: 'single', color: 'green', padding: 1, width: 70 })); } /** * Standard error message display */ function showErrorMessage(title, details, suggestions) { const content = [ `❌ ${title}`, '', ...details ]; if (suggestions && suggestions.length > 0) { content.push('', '💡 Try these solutions:', ...suggestions.map(suggestion => `• ${suggestion}`)); } console.log((0, visual_1.createBox)(content, { title: '⚠️ Error', style: 'single', color: 'red', padding: 1, width: 70 })); } /** * Standard "no items found" message with helpful suggestions */ function showNoItemsFound(itemType, suggestions) { console.log((0, visual_1.createBox)([ `🔍 No ${itemType} Found`, '', `No ${itemType} were found in your account.`, '', '💡 To get started:', ...suggestions.map(suggestion => `• ${suggestion}`) ], { title: '📋 Getting Started', style: 'single', color: 'blue', padding: 1, width: 70 })); }