You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
1.0 KiB
27 lines
1.0 KiB
#!/usr/bin/env node
|
|
|
|
const {checkSimpleGitHooksInDependencies, getProjectRootDirectoryFromNodeModules, setHooksFromConfig} = require("./simple-git-hooks");
|
|
|
|
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()
|
|
|