mirror of
https://github.com/mapbox/mapbox-agent-skills.git
synced 2026-09-14 20:16:39 +08:00
58 lines
1.6 KiB
JavaScript
58 lines
1.6 KiB
JavaScript
#!/usr/bin/env node
|
|
// Setup git hooks for local CI checks
|
|
|
|
import { existsSync, copyFileSync, chmodSync, constants } from 'fs';
|
|
import { join } from 'path';
|
|
import { fileURLToPath } from 'url';
|
|
import { dirname } from 'path';
|
|
|
|
const __filename = fileURLToPath(import.meta.url);
|
|
const __dirname = dirname(__filename);
|
|
const rootDir = join(__dirname, '..');
|
|
|
|
const HOOKS_DIR = join(rootDir, '.git', 'hooks');
|
|
const SOURCE_HOOKS_DIR = join(rootDir, '.githooks');
|
|
|
|
console.log('🔧 Setting up git hooks...');
|
|
|
|
// Make sure .git/hooks directory exists
|
|
if (!existsSync(HOOKS_DIR)) {
|
|
console.error(
|
|
'Error: .git/hooks directory not found. Are you in the repository root?'
|
|
);
|
|
process.exit(1);
|
|
}
|
|
|
|
// Copy pre-push hook
|
|
console.log('📋 Installing pre-push hook...');
|
|
const sourceHook = join(SOURCE_HOOKS_DIR, 'pre-push');
|
|
const targetHook = join(HOOKS_DIR, 'pre-push');
|
|
|
|
try {
|
|
copyFileSync(sourceHook, targetHook);
|
|
|
|
// Make executable (Unix-like systems)
|
|
// On Windows, this is a no-op but won't error
|
|
try {
|
|
chmodSync(targetHook, 0o755);
|
|
} catch (chmodError) {
|
|
// Ignore chmod errors on Windows
|
|
}
|
|
|
|
console.log('✅ Pre-push hook installed');
|
|
} catch (error) {
|
|
console.error(`Error installing hook: ${error.message}`);
|
|
process.exit(1);
|
|
}
|
|
|
|
console.log('');
|
|
console.log('✨ Git hooks setup complete!');
|
|
console.log('');
|
|
console.log('The pre-push hook will now run before every push to ensure:');
|
|
console.log(' - Code is properly formatted');
|
|
console.log(' - No spelling errors');
|
|
console.log(' - Markdown is valid');
|
|
console.log(' - Skills are valid');
|
|
console.log('');
|
|
console.log('To bypass the hook (not recommended), use: git push --no-verify');
|