-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprepare.js
43 lines (33 loc) · 920 Bytes
/
prepare.js
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
// Credit https://sonspring.com/journal/husky-v5-and-npm-prepare/
// =======
// Import.
// =======
const { execSync } = require('child_process');
const { existsSync } = require('fs');
// ===========
// File paths.
// ===========
const FILE_COMMIT = './.husky/pre-commit';
const FILE_HUSKY = './.husky/_/husky.sh';
// ==============
// Husky install.
// ==============
const CLI_HUSKY = 'npx husky install';
if (!existsSync(FILE_HUSKY)) {
global.console.log(CLI_HUSKY);
execSync(CLI_HUSKY);
}
// ====================
// Add pre-commit hook.
// ====================
const PRECOMMITS = [
'npx husky add .husky/pre-commit "yarn prettier/check"',
'npx husky add .husky/pre-commit "yarn build"',
'npx husky add .husky/commit-msg "npx --no -- commitlint --edit ${1}"'
]
if (!existsSync(FILE_COMMIT)) {
for (let precommit of PRECOMMITS) {
global.console.log(precommit);
execSync(precommit);
}
}