basant307/AI_Governance_Project
045
1import c from 'child_process'2import f, { readdir, writeFileSync as w } from 'fs'3import p from 'path'4 5let l = [ 'pre-commit', 'pre-merge-commit', 'prepare-commit-msg', 'commit-msg', 'post-commit', 'applypatch-msg', 'pre-applypatch', 'post-applypatch', 'pre-rebase', 'post-rewrite', 'post-checkout', 'post-merge', 'pre-push', 'pre-auto-gc' ],6 msg = `echo "husky - DEPRECATED\n\nPlease remove the following two lines from $0:\n\n#!/usr/bin/env sh\n. \\"\\$(dirname -- \\"\\$0\\")/_/husky.sh\\"\n\nThey WILL FAIL in v10.0.0\n"`7 8export default (d = '.husky') => {9 if (process.env.HUSKY === '0') return 'HUSKY=0 skip install'10 if (d.includes('..')) return '.. not allowed'11 if (!f.existsSync('.git')) return `.git can't be found`12 13 let _ = (x = '') => p.join(d, '_', x)14 let { status: s, stderr: e } = c.spawnSync('git', ['config', 'core.hooksPath', `${d}/_`])15 if (s == null) return 'git command not found'16 if (s) return '' + e17 18 f.rmSync(_('husky.sh'), { force: true })19 f.mkdirSync(_(), { recursive: true })20 w(_('.gitignore'), '*')21 f.copyFileSync(new URL('husky', import.meta.url), _('h'))22 l.forEach(h => w(_(h), `#!/usr/bin/env sh\n. "\$(dirname "\$0")/h"`, { mode: 0o755 }))23 w(_('husky.sh'), msg)24 return ''25}26 