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