Skip to content

Commit 505bd2e

Browse files
committed
Update
1 parent 9a01b19 commit 505bd2e

1 file changed

Lines changed: 20 additions & 13 deletions

File tree

src/index.js

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ var exec = require('child_process').exec
44
var normalize = require('normalize-path')
55
var findParentDir = require('find-parent-dir')
66
var hooks = require('./hooks.json')
7-
7+
var pkg = require('../package.json')
88

99
function write (filename, data) {
1010
fs.writeFileSync(filename, data)
@@ -45,17 +45,18 @@ function getHookScript (hookName, relativePath, cmd) {
4545
// Hook script
4646
var arr = [
4747
'#!/bin/sh',
48-
'# husky'
48+
'# husky ' + pkg.version,
49+
''
4950
]
5051

5152
arr = arr.concat([
5253
'cd ' + normalizedPath,
53-
5454
// Fix for issue #16 #24
5555
// Test if script is defined in package.json
5656
'[ -f package.json ] && cat package.json | grep -q \'"' + cmd + '"\\s*:\'',
5757
// package.json or script can't be found exit
5858
'[ $? -ne 0 ] && exit 0',
59+
''
5960
])
6061

6162
// On OS X and Linux, try to use nvm if it's installed
@@ -64,13 +65,6 @@ function getHookScript (hookName, relativePath, cmd) {
6465
var home = process.env.HOME
6566

6667
if (process.platform === 'darwin') {
67-
// If nvm was installed using homebrew,
68-
// nvm script will be found in /usr/local/opt/nvm
69-
arr = arr.concat([
70-
'BREW_NVM_DIR="/usr/local/opt/nvm"',
71-
'[ -s "$BREW_NVM_DIR/nvm.sh" ] && . "$BREW_NVM_DIR/nvm.sh"'
72-
])
73-
7468
// Add
7569
// Brew standard installation path /use/local/bin
7670
// Node standard installation path /usr/local
@@ -81,18 +75,31 @@ function getHookScript (hookName, relativePath, cmd) {
8175
])
8276
}
8377

78+
if (process.platform === 'darwin') {
79+
arr = arr.concat([
80+
'if ! [ command -v npm >/dev/null 2>&1 ];',
81+
'then',
82+
' BREW_NVM_DIR="/usr/local/opt/nvm"',
83+
' [ -s "$BREW_NVM_DIR/nvm.sh" ] && . "$BREW_NVM_DIR/nvm.sh"',
84+
' command -v nvm >/dev/null 2>&1 && [ -f .nvmrc ] && nvm use',
85+
'fi',
86+
''
87+
])
88+
}
89+
8490
arr = arr.concat([
8591
// Test if npm is not already in path
92+
// If npm isn't in path, try to load it using nvm
8693
'if ! [ command -v npm >/dev/null 2>&1 ];',
8794
'then',
88-
// If npm isn't in path, try to load it using nvm
8995
// If nvm was installed using install script, nvm script will be found in $NVM_DIR
9096
' export NVM_DIR="' + home + '/.nvm"',
9197
// This will load default Node version or version specified by .nvmrc
9298
' [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"',
9399
// Test if nvm is in PATH and load version specified by .nvmrc
94100
' command -v nvm >/dev/null 2>&1 && [ -f .nvmrc ] && nvm use',
95-
'fi'
101+
'fi',
102+
''
96103
])
97104
} else {
98105
// Add
@@ -198,4 +205,4 @@ function uninstallFrom (huskyDir) {
198205
module.exports = {
199206
installFrom: installFrom,
200207
uninstallFrom: uninstallFrom
201-
}
208+
}

0 commit comments

Comments
 (0)