-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup-hooks.js
More file actions
executable file
·54 lines (43 loc) · 1.99 KB
/
Copy pathsetup-hooks.js
File metadata and controls
executable file
·54 lines (43 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env node
/**
* Setup script for Cursor-Cortex Git hooks
* This script installs the post-commit hook to automatically add commit separators
* and the pre-commit hook to run linting before commits
*/
import fs from 'fs/promises';
import path from 'path';
import { execSync } from 'child_process';
async function setupHooks() {
try {
console.log('Setting up Cursor-Cortex Git hooks...');
// Get Git repository root
const gitRoot = execSync('git rev-parse --show-toplevel').toString().trim();
// Create .git/hooks directory if it doesn't exist
const hooksDir = path.join(gitRoot, '.git', 'hooks');
try {
await fs.access(hooksDir);
} catch (error) {
console.log('Creating hooks directory due to:', error.message);
await fs.mkdir(hooksDir, { recursive: true });
}
// Copy our post-commit hook
const sourcePostCommitHook = path.join(gitRoot, 'hooks', 'post-commit');
const targetPostCommitHook = path.join(hooksDir, 'post-commit');
console.log(`Copying post-commit hook from ${sourcePostCommitHook} to ${targetPostCommitHook}...`);
await fs.copyFile(sourcePostCommitHook, targetPostCommitHook);
await fs.chmod(targetPostCommitHook, 0o755); // Make executable
// Copy our pre-commit hook
const sourcePreCommitHook = path.join(gitRoot, 'hooks', 'pre-commit');
const targetPreCommitHook = path.join(hooksDir, 'pre-commit');
console.log(`Copying pre-commit hook from ${sourcePreCommitHook} to ${targetPreCommitHook}...`);
await fs.copyFile(sourcePreCommitHook, targetPreCommitHook);
await fs.chmod(targetPreCommitHook, 0o755); // Make executable
console.log('Git hooks installed successfully!');
console.log('Now, when you make commits, linting will be performed before the commit');
console.log('and branch notes will automatically get commit separators.');
} catch (error) {
console.error('Error setting up Git hooks:', error.message);
process.exit(1);
}
}
setupHooks();