forked from toplenboren/simple-git-hooks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
postinstall.js
31 lines (25 loc) · 1.07 KB
/
postinstall.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
#!/usr/bin/env node
const {checkSimpleGitHooksInDependencies, getProjectRootDirectoryFromNodeModules, setHooksFromConfig} = require("./simple-git-hooks");
/**
* Creates the pre-commit from command in config by default
*/
function postinstall() {
let projectDirectory;
/* When script is run after install, the process.cwd() would be like <project_folder>/node_modules/simple-git-hooks
Here we try to get the original project directory by going upwards by 2 levels
If we were not able to get new directory we assume, we are already in the project root */
const parsedProjectDirectory = getProjectRootDirectoryFromNodeModules(process.cwd())
if (parsedProjectDirectory !== undefined) {
projectDirectory = parsedProjectDirectory
} else {
projectDirectory = process.cwd()
}
if (checkSimpleGitHooksInDependencies(projectDirectory)) {
try {
setHooksFromConfig(projectDirectory)
} catch (err) {
console.log('[ERROR] Was not able to set git hooks. Reason: ' + err)
}
}
}
postinstall()