1const path = require('path');
2const fs = require('fs');
3
4const hookSource = path.resolve(__dirname, '../node_modules/husky-v4/sh/husky.sh');
5const hook = path.resolve(__dirname, '../.git/hooks/husky.sh');
6const localHook = path.resolve(__dirname, '../.git/hooks/husky.local.sh');
7const gitConfig = path.resolve(__dirname, '../.git/config');
8
9let script = fs.readFileSync(hookSource, { encoding: 'utf-8' });
10script = script.replace(`$(basename "$0")`, `$(basename "$0" .sh)`);
11
12let config = fs.readFileSync(gitConfig, { encoding: 'utf-8' });
13config = config.replace(/\s*hooksPath\s*=\s*\.husky\n?/g, '\n');
14
15fs.writeFileSync(hook, script);
16fs.writeFileSync(gitConfig, config);
17
18fs.writeFileSync(localHook, 'packageManager=yarn\n' + 'cd "."\n');