UNPKG

git-suggest

Version:

A lightweight command-line tool that automatically generates contextual, high-quality Git commit messages based on your staged code changes. Powered by GitHub Copilot CLI, it helps you write smarter commits with less typing.

121 lines 5.7 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.checkPrerequisites = checkPrerequisites; exports.installPrerequisites = installPrerequisites; const child_process_1 = require("child_process"); const chalk_1 = __importDefault(require("chalk")); async function checkPrerequisites(verbose = false) { const checks = [ { name: 'Git', command: 'git --version', required: true }, { name: 'GitHub CLI', command: 'gh --version', required: true }, { name: 'GitHub Copilot CLI', command: 'gh copilot --help', required: true } ]; const results = []; for (const check of checks) { try { const output = (0, child_process_1.execSync)(check.command, { encoding: 'utf8', stdio: 'pipe', timeout: 5000 }); const version = output.split('\n')[0].trim(); results.push({ name: check.name, installed: true, version }); if (verbose) { console.log(chalk_1.default.green(`✓ ${check.name}: ${version}`)); } } catch (error) { const errorMessage = error instanceof Error ? error.message : 'Unknown error'; results.push({ name: check.name, installed: false, error: errorMessage }); if (verbose) { console.log(chalk_1.default.red(`✗ ${check.name}: Not installed or not accessible`)); } } } const missingRequired = results.filter(r => !r.installed); if (missingRequired.length > 0) { console.error(chalk_1.default.red('\nMissing required dependencies:')); for (const missing of missingRequired) { console.error(chalk_1.default.red(` ✗ ${missing.name}`)); switch (missing.name) { case 'Git': console.error(chalk_1.default.yellow(' Install from: https://git-scm.com/downloads')); break; case 'GitHub CLI': console.error(chalk_1.default.yellow(' Install with: npm install -g @github/gh')); console.error(chalk_1.default.yellow(' Or visit: https://cli.github.com/')); break; case 'GitHub Copilot CLI': console.error(chalk_1.default.yellow(' Install with: gh extension install github/gh-copilot')); console.error(chalk_1.default.yellow(' Requires GitHub Copilot subscription')); break; } } throw new Error(`Missing ${missingRequired.length} required dependencies. Please install them and try again.`); } // Check GitHub CLI authentication try { (0, child_process_1.execSync)('gh auth status', { stdio: 'pipe', timeout: 5000 }); if (verbose) { console.log(chalk_1.default.green('✓ GitHub CLI: Authenticated')); } } catch { console.warn(chalk_1.default.yellow('⚠ GitHub CLI: Not authenticated. Run "gh auth login" to authenticate.')); } } async function installPrerequisites() { console.log(chalk_1.default.blue('Installing prerequisites...')); const platform = process.platform; try { // Check if GitHub CLI is installed try { (0, child_process_1.execSync)('gh --version', { stdio: 'pipe' }); console.log(chalk_1.default.green('✓ GitHub CLI already installed')); } catch { console.log(chalk_1.default.yellow('Installing GitHub CLI...')); if (platform === 'darwin') { // macOS - try homebrew first, then npm try { (0, child_process_1.execSync)('brew install gh', { stdio: 'inherit' }); } catch { (0, child_process_1.execSync)('npm install -g @github/gh', { stdio: 'inherit' }); } } else if (platform === 'win32') { // Windows - use npm (0, child_process_1.execSync)('npm install -g @github/gh', { stdio: 'inherit' }); } else { // Linux - use npm (0, child_process_1.execSync)('npm install -g @github/gh', { stdio: 'inherit' }); } console.log(chalk_1.default.green('✓ GitHub CLI installed')); } // Install GitHub Copilot CLI extension try { (0, child_process_1.execSync)('gh copilot --help', { stdio: 'pipe' }); console.log(chalk_1.default.green('✓ GitHub Copilot CLI already installed')); } catch { console.log(chalk_1.default.yellow('Installing GitHub Copilot CLI extension...')); (0, child_process_1.execSync)('gh extension install github/gh-copilot', { stdio: 'inherit' }); console.log(chalk_1.default.green('✓ GitHub Copilot CLI extension installed')); } console.log(chalk_1.default.green('\n✓ All prerequisites installed successfully!')); console.log(chalk_1.default.blue('\nNext steps:')); console.log(chalk_1.default.blue('1. Authenticate with GitHub: gh auth login')); console.log(chalk_1.default.blue('2. Ensure you have GitHub Copilot subscription')); console.log(chalk_1.default.blue('3. Run: git-suggest setup')); } catch (error) { console.error(chalk_1.default.red('Failed to install prerequisites:'), error); throw error; } } //# sourceMappingURL=prerequisites.js.map