UNPKG

gitset

Version:

Enhanced git init with user configuration management

170 lines • 6.33 kB
import inquirer from 'inquirer'; import { ValidationUtils } from '../utils/validation.js'; import { MESSAGES, CLI_CONFIG } from '../config/constants.js'; export class UserPrompts { validationUtils; constructor(validationUtils) { this.validationUtils = validationUtils || new ValidationUtils(); } async promptGitInstallation() { const response = await inquirer.prompt([ { type: 'confirm', name: 'installGit', message: MESSAGES.prompts.gitInstall, default: true } ]); return response.installGit; } async promptDirectory(defaultDirectory = CLI_CONFIG.defaultDirectoryPlaceholder) { // Show current working directory const currentDir = process.cwd(); console.log(`\nšŸ“ Current directory: ${currentDir}`); const response = await inquirer.prompt([ { type: 'input', name: 'directory', message: MESSAGES.prompts.directory, default: defaultDirectory, validate: async (input) => { if (!input.trim()) { return MESSAGES.prompts.directoryRequired; } const validation = await this.validationUtils.validateDirectoryPath(input); if (!validation.valid) { return validation.errors.join(', '); } return true; } } ]); // Check validation again to show warnings after input is confirmed const validation = await this.validationUtils.validateDirectoryPath(response.directory.trim()); if (validation.warnings && validation.warnings.length > 0) { validation.warnings.forEach(warning => { if (warning.includes('will be created')) { console.log(`šŸ“‚ ${warning}`); } else if (warning.includes('not empty')) { console.log(`āš ļø ${warning}`); } else { console.log(`ā„¹ļø ${warning}`); } }); } return response.directory.trim(); } async promptUserInfo(globalConfig) { console.log(`\n${MESSAGES.prompts.userInfo}`); const questions = [ { type: 'input', name: 'name', message: MESSAGES.prompts.name, default: globalConfig?.name || '', validate: (input) => { const validation = this.validationUtils.validateUsername(input); if (!validation.valid) { return validation.errors.join(', '); } if (validation.warnings && validation.warnings.length > 0) { console.log(`āš ļø ${validation.warnings.join(', ')}`); } return true; } }, { type: 'input', name: 'email', message: MESSAGES.prompts.email, default: globalConfig?.email || '', validate: (input) => { const validation = this.validationUtils.validateEmail(input); if (!validation.valid) { return validation.errors.join(', '); } return true; } } ]; const responses = await inquirer.prompt(questions); return { name: responses.name.trim(), email: responses.email.trim(), source: 'user-input' }; } async confirmConfiguration(directory, userInfo) { console.log(`\n${MESSAGES.prompts.configSummary}`); console.log(` Directory: ${directory}`); console.log(` Name: ${userInfo.name}`); console.log(` Email: ${userInfo.email}`); const response = await inquirer.prompt([ { type: 'confirm', name: 'proceed', message: MESSAGES.prompts.confirm, default: true } ]); return response.proceed; } async promptRetry(action) { const response = await inquirer.prompt([ { type: 'confirm', name: 'retry', message: MESSAGES.prompts.retry.replace('{action}', action), default: true } ]); return response.retry; } async promptGitRepoReinitialize() { const response = await inquirer.prompt([ { type: 'confirm', name: 'reinitialize', message: MESSAGES.prompts.gitRepoExists, default: false } ]); return response.reinitialize; } showExitMessage() { console.log(`\n${MESSAGES.prompts.exitMessage}`); } async selectInstallationMethod(availableMethods) { const response = await inquirer.prompt([ { type: 'list', name: 'method', message: MESSAGES.prompts.selectMethod, choices: availableMethods.map(method => ({ name: this.getInstallationMethodDescription(method), value: method })) } ]); return response.method; } getInstallationMethodDescription(method) { const descriptions = { 'homebrew': 'šŸŗ Homebrew (recommended for macOS)', 'xcode-tools': 'šŸ”Ø Xcode Command Line Tools', 'apt': 'šŸ“¦ APT (Ubuntu/Debian)', 'yum': 'šŸ“¦ YUM (RHEL/CentOS)', 'dnf': 'šŸ“¦ DNF (Fedora)', 'pacman': 'šŸ“¦ Pacman (Arch Linux)', 'zypper': 'šŸ“¦ Zypper (openSUSE)', 'winget': 'šŸ“¦ Windows Package Manager', 'chocolatey': 'šŸ« Chocolatey', 'scoop': 'šŸ„„ Scoop', 'download': 'ā¬‡ļø Manual download and install' }; return descriptions[method] || method; } } //# sourceMappingURL=prompts.js.map