UNPKG

qraft

Version:

A powerful CLI tool to qraft structured project setups from GitHub template repositories

332 lines • 14.3 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ConfirmationWorkflows = void 0; const chalk_1 = __importDefault(require("chalk")); const readline = __importStar(require("readline")); class ConfirmationWorkflows { constructor() { this.rl = readline.createInterface({ input: process.stdin, output: process.stdout }); } async confirmSensitiveFiles(warnings) { console.log(chalk_1.default.red('\n🚨 Sensitive Files Detected')); console.log(chalk_1.default.gray('─'.repeat(50))); warnings.forEach((warning, index) => { const severityColor = this.getSeverityColor(warning.severity); const severityIcon = this.getSeverityIcon(warning.severity); console.log(`\n${index + 1}. ${severityColor(`${severityIcon} ${warning.file}`)}`); console.log(` ${chalk_1.default.gray('Reason:')} ${warning.reason}`); console.log(` ${chalk_1.default.gray('Severity:')} ${severityColor(warning.severity.toUpperCase())}`); if (warning.suggestions.length > 0) { console.log(` ${chalk_1.default.gray('Suggestions:')}`); warning.suggestions.forEach(suggestion => { console.log(` ${chalk_1.default.gray('•')} ${suggestion}`); }); } }); console.log(chalk_1.default.gray('\n─'.repeat(50))); const criticalCount = warnings.filter(w => w.severity === 'critical').length; const highCount = warnings.filter(w => w.severity === 'high').length; let message = `Found ${warnings.length} sensitive file(s)`; if (criticalCount > 0) { message += ` (${criticalCount} critical)`; } if (highCount > 0) { message += ` (${highCount} high risk)`; } const options = { title: 'Sensitive Files Warning', message, warningLevel: criticalCount > 0 ? 'danger' : highCount > 0 ? 'warning' : 'info', defaultChoice: false, requireExplicitConfirmation: criticalCount > 0, showAlternatives: true, alternatives: [ 'Review and remove sensitive files', 'Add files to .gitignore', 'Use a different source directory', 'Continue with caution (not recommended)' ] }; return this.showConfirmation(options); } async confirmConflictResolution(conflicts) { console.log(chalk_1.default.yellow('\nāš ļø Conflicts Detected')); console.log(chalk_1.default.gray('─'.repeat(50))); conflicts.forEach((conflict, index) => { const riskColor = this.getRiskColor(conflict.riskLevel); const riskIcon = this.getRiskIcon(conflict.riskLevel); console.log(`\n${index + 1}. ${riskColor(`${riskIcon} ${conflict.type.replace('_', ' ').toUpperCase()}`)}`); console.log(` ${chalk_1.default.gray('Description:')} ${conflict.description}`); console.log(` ${chalk_1.default.gray('Risk Level:')} ${riskColor(conflict.riskLevel.toUpperCase())}`); console.log(` ${chalk_1.default.gray('Affected Files:')} ${conflict.affectedFiles.length} file(s)`); if (conflict.affectedFiles.length <= 5) { conflict.affectedFiles.forEach(file => { console.log(` ${chalk_1.default.gray('•')} ${file}`); }); } else { conflict.affectedFiles.slice(0, 3).forEach(file => { console.log(` ${chalk_1.default.gray('•')} ${file}`); }); console.log(` ${chalk_1.default.gray('•')} ... and ${conflict.affectedFiles.length - 3} more`); } if (conflict.recommendations.length > 0) { console.log(` ${chalk_1.default.gray('Recommendations:')}`); conflict.recommendations.forEach(rec => { console.log(` ${chalk_1.default.gray('•')} ${rec}`); }); } }); console.log(chalk_1.default.gray('\n─'.repeat(50))); const criticalCount = conflicts.filter(c => c.riskLevel === 'critical').length; const highCount = conflicts.filter(c => c.riskLevel === 'high').length; let message = `Found ${conflicts.length} conflict(s)`; if (criticalCount > 0) { message += ` (${criticalCount} critical)`; } if (highCount > 0) { message += ` (${highCount} high risk)`; } const options = { title: 'Conflict Resolution', message, warningLevel: criticalCount > 0 ? 'danger' : highCount > 0 ? 'warning' : 'info', defaultChoice: criticalCount === 0, requireExplicitConfirmation: criticalCount > 0, showAlternatives: true, alternatives: [ 'Review conflicts manually', 'Use backup and replace strategy', 'Skip conflicting files', 'Cancel operation' ] }; return this.showConfirmation(options); } async confirmRepositoryOperation(operation, details) { const operationTitles = { fork: 'šŸ“ Fork Repository', create_pr: 'šŸ“ Create Pull Request', push: 'šŸ“¤ Push Changes', overwrite: 'āš ļø Overwrite Existing Box' }; const operationMessages = { fork: `Fork repository ${details.repository} to your account`, create_pr: `Create pull request in ${details.repository}`, push: `Push changes to ${details.repository}${details.branch ? ` (${details.branch})` : ''}`, overwrite: `Overwrite existing box in ${details.repository}` }; console.log(chalk_1.default.cyan(`\n${operationTitles[operation]}`)); console.log(chalk_1.default.gray('─'.repeat(50))); console.log(`${chalk_1.default.yellow('Operation:')} ${operationMessages[operation]}`); if (details.description) { console.log(`${chalk_1.default.yellow('Description:')} ${details.description}`); } if (details.impact && details.impact.length > 0) { console.log(`${chalk_1.default.yellow('Impact:')}`); details.impact.forEach(item => { console.log(` ${chalk_1.default.gray('•')} ${item}`); }); } const options = { title: operationTitles[operation], message: operationMessages[operation], warningLevel: operation === 'overwrite' ? 'warning' : 'info', defaultChoice: operation !== 'overwrite', requireExplicitConfirmation: operation === 'overwrite' }; return this.showConfirmation(options); } async confirmDryRunResults(summary) { console.log(chalk_1.default.cyan('\nšŸ“‹ Operation Preview')); console.log(chalk_1.default.gray('─'.repeat(50))); console.log(`${chalk_1.default.yellow('Operation:')} ${summary.operation}`); console.log(`${chalk_1.default.yellow('Files Affected:')} ${summary.filesAffected}`); console.log(`${chalk_1.default.yellow('Estimated Time:')} ${summary.estimatedTime}`); const riskColor = this.getRiskColor(summary.riskLevel); console.log(`${chalk_1.default.yellow('Risk Level:')} ${riskColor(summary.riskLevel.toUpperCase())}`); if (summary.warnings.length > 0) { console.log(`${chalk_1.default.yellow('Warnings:')}`); summary.warnings.forEach(warning => { console.log(` ${chalk_1.default.red('⚠')} ${warning}`); }); } const options = { title: 'Confirm Operation', message: `Proceed with ${summary.operation.toLowerCase()}?`, warningLevel: summary.riskLevel === 'critical' ? 'danger' : summary.riskLevel === 'high' ? 'warning' : 'info', defaultChoice: summary.riskLevel !== 'critical', requireExplicitConfirmation: summary.riskLevel === 'critical' }; return this.showConfirmation(options); } async showConfirmation(options) { console.log(chalk_1.default.gray('\n─'.repeat(50))); if (options.details && options.details.length > 0) { options.details.forEach(detail => { console.log(`${chalk_1.default.gray('•')} ${detail}`); }); console.log(); } if (options.showAlternatives && options.alternatives && options.alternatives.length > 0) { console.log(chalk_1.default.cyan('Alternatives:')); options.alternatives.forEach((alt, index) => { console.log(` ${chalk_1.default.gray(`${index + 1}.`)} ${alt}`); }); console.log(); } const warningColor = this.getWarningColor(options.warningLevel || 'info'); const prompt = options.requireExplicitConfirmation ? 'Type "yes" to confirm, or "no" to cancel' : options.defaultChoice ? 'Continue? (Y/n)' : 'Continue? (y/N)'; console.log(warningColor(`${options.message}`)); const answer = await this.question(`${prompt}: `); let confirmed = false; let choice = 'cancel'; if (options.requireExplicitConfirmation) { if (answer.toLowerCase() === 'yes') { confirmed = true; choice = 'yes'; } else if (answer.toLowerCase() === 'no') { confirmed = false; choice = 'no'; } else { confirmed = false; choice = 'cancel'; } } else { const input = answer.trim().toLowerCase(); if (!input) { confirmed = options.defaultChoice || false; choice = confirmed ? 'yes' : 'no'; } else if (input === 'y' || input === 'yes') { confirmed = true; choice = 'yes'; } else if (input === 'n' || input === 'no') { confirmed = false; choice = 'no'; } else { confirmed = false; choice = 'cancel'; } } this.close(); return { confirmed, choice, timestamp: Date.now() }; } question(prompt) { return new Promise((resolve) => { this.rl.question(prompt, (answer) => { resolve(answer); }); }); } getSeverityColor(severity) { switch (severity) { case 'critical': return chalk_1.default.red.bold; case 'high': return chalk_1.default.red; case 'medium': return chalk_1.default.yellow; case 'low': return chalk_1.default.blue; default: return chalk_1.default.gray; } } getSeverityIcon(severity) { switch (severity) { case 'critical': return 'šŸ”“'; case 'high': return '🟠'; case 'medium': return '🟔'; case 'low': return 'šŸ”µ'; default: return '⚪'; } } getRiskColor(risk) { switch (risk) { case 'critical': return chalk_1.default.red.bold; case 'high': return chalk_1.default.red; case 'medium': return chalk_1.default.yellow; case 'low': return chalk_1.default.green; default: return chalk_1.default.gray; } } getRiskIcon(risk) { switch (risk) { case 'critical': return 'šŸ’€'; case 'high': return 'āš ļø'; case 'medium': return '⚔'; case 'low': return 'āœ…'; default: return 'ā„¹ļø'; } } getWarningColor(level) { switch (level) { case 'danger': return chalk_1.default.red.bold; case 'warning': return chalk_1.default.yellow; case 'info': return chalk_1.default.cyan; default: return chalk_1.default.white; } } close() { this.rl.close(); } // Test helper methods async confirmationDryRun(_type, mockChoice = 'yes') { return { confirmed: mockChoice === 'yes', choice: mockChoice, timestamp: Date.now() }; } } exports.ConfirmationWorkflows = ConfirmationWorkflows; //# sourceMappingURL=confirmationWorkflows.js.map