UNPKG

@alvinveroy/codecompass

Version:

AI-powered MCP server for codebase navigation and LLM prompt optimization

54 lines (53 loc) 2.55 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const fs_extra_1 = __importDefault(require("fs-extra")); const path_1 = __importDefault(require("path")); const projectRoot = path_1.default.resolve(__dirname, '../../'); const hooksSourceDir = path_1.default.join(projectRoot, 'src', 'templates', 'hooks'); const gitHooksDir = path_1.default.join(projectRoot, '.git', 'hooks'); const availableHooks = ['post-commit']; async function installHooks() { if (!fs_extra_1.default.existsSync(path_1.default.join(projectRoot, '.git'))) { process.stderr.write('This does not appear to be a Git repository. .git directory not found.\n'); process.exit(1); } if (!fs_extra_1.default.existsSync(gitHooksDir)) { process.stdout.write(`.git/hooks directory not found. Creating it at ${gitHooksDir}\n`); try { await fs_extra_1.default.ensureDir(gitHooksDir); } catch (dirError) { const error = dirError instanceof Error ? dirError : new Error(String(dirError)); process.stderr.write(`Failed to create .git/hooks directory: ${error.message}\n`); process.exit(1); } } for (const hookName of availableHooks) { const sourceHookPath = path_1.default.join(hooksSourceDir, hookName); const destHookPath = path_1.default.join(gitHooksDir, hookName); if (!fs_extra_1.default.existsSync(sourceHookPath)) { process.stdout.write(`Hook template ${sourceHookPath} not found. Skipping ${hookName}.\n`); continue; } try { await fs_extra_1.default.copy(sourceHookPath, destHookPath, { overwrite: true }); await fs_extra_1.default.chmod(destHookPath, '755'); process.stdout.write(`Installed git hook: ${hookName} to ${destHookPath}\n`); } catch (error) { const err = error instanceof Error ? error : new Error(String(error)); process.stderr.write(`Failed to install git hook ${hookName}: ${err.message}\n`); } } process.stdout.write('Git hook installation process finished.\n'); } if (require.main === module) { installHooks().catch((err) => { const error = err instanceof Error ? err : new Error(String(err)); process.stderr.write(`Error during hook installation: ${error.message}\n`); process.exit(1); }); }