#!/usr/bin/env node 'use strict'; // {{generated_message}} var fs = require('fs'); var path = require('path'); var nodeModulesPath = '{{node_modules_path}}'; var ghooks = getGhooksEntryPoint(); if (checkForGHooks(ghooks)) { require(ghooks)(nodeModulesPath, __filename); } function getGhooksEntryPoint() { try { require('ghooks'); return 'ghooks'; } catch (e) { return getGhooksAbsoluteEntryPoint(); } } function getGhooksAbsoluteEntryPoint() { var worktree = getWorkTree(); if (worktree) { return path.resolve(__dirname, '../', worktree, 'node_modules', 'ghooks'); } return path.resolve(nodeModulesPath, 'ghooks'); } function checkForGHooks(ghooksPath) { try { require(ghooksPath); } catch (e) { warnAboutGHooks(); return false; } return true; } function getWorkTree() { try { return getWorkTreeFromConfig(getConfigFileContent()); } catch (e) { return null; } } function getConfigFileContent() { var configFile = path.resolve(__dirname, '../config'); var fileStat = fs.statSync(configFile); if (fileStat && fileStat.isFile()) { return fs.readFileSync(configFile, 'utf8'); } return ''; } function getWorkTreeFromConfig(configFileContent) { var worktreeRegEx = /\[core\][^]{0,}worktree = ([^\n]{1,})[^]{0,}/; return worktreeRegEx.test(configFileContent) ? configFileContent.replace(worktreeRegEx, '$1') : ''; } function warnAboutGHooks() { console.warn( // eslint-disable-line no-console 'ghooks not found!\n' + 'Make sure you have it installed on your "node_modules".\n' + 'Skipping git hooks.'); }