diff --git a/.npm/bin/index.js b/.npm/bin/index.js index 1887e243..2ada9ce7 100755 --- a/.npm/bin/index.js +++ b/.npm/bin/index.js @@ -5,26 +5,13 @@ var path = require('path'); var command_args = process.argv.slice(2); -function spawnCommand(binaryExecutable) { - var child = spawn( - path.join(__dirname, binaryExecutable), - command_args, - { stdio: [process.stdin, process.stdout, process.stderr] }); +var child = spawn( + path.join(__dirname, 'lefthook'), + command_args, + { stdio: [process.stdin, process.stdout, process.stderr] }); - child.on('close', function (code) { - if (code !== 0) { - process.exit(1); - } - }); -} - -if (process.platform === 'darwin') { - spawnCommand('lefthook-mac'); -} else if (process.platform === 'linux') { - spawnCommand('lefthook-linux'); -} else if (process.platform === 'win32') { - spawnCommand('lefthook-win.exe'); -} else { - console.log("Unsupported OS"); - process.exit(1); -} +child.on('close', function (code) { + if (code !== 0) { + process.exit(1); + } +}); diff --git a/.npm/bin/lefthook b/.npm/bin/lefthook new file mode 100755 index 00000000..6ab277d0 --- /dev/null +++ b/.npm/bin/lefthook @@ -0,0 +1,13 @@ +#!/bin/sh + +dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)" + +if [[ "$OSTYPE" == "linux-gnu"* ]]; then + $dir/lefthook-linux $@ +elif [[ "$OSTYPE" == "darwin"* ]]; then + $dir/lefthook-mac $@ +elif [[ "$OSTYPE" == "cygwin" ]] || [[ "$OSTYPE" == "msys" ]] || [[ "$OSTYPE" == "win32" ]]; then + $dir/lefthook-win.exe $@ +else + Unsupported OS +fi diff --git a/cmd/add.go b/cmd/add.go index afa50732..8d197a00 100644 --- a/cmd/add.go +++ b/cmd/add.go @@ -69,12 +69,17 @@ if [ -t 1 ] ; then exec < /dev/tty ; # <- enables interactive shell fi +dir="$(cd "$(dirname $(dirname $(dirname "${BASH_SOURCE[0]}")))" >/dev/null 2>&1 && pwd)" + ` + autoInstall(hookName, fs) + "\n" + "cmd=\"lefthook run " + hookName + " $@\"" + ` if lefthook -h >/dev/null 2>&1 then eval $cmd +elif test -f "$dir/node_modules/@arkweid/lefthook/bin/lefthook" +then + eval $dir/node_modules/@arkweid/lefthook/bin/$cmd elif bundle exec lefthook -h >/dev/null 2>&1 then bundle exec $cmd @@ -119,6 +124,9 @@ func autoInstall(hookName string, fs afero.Fs) string { if lefthook -h >/dev/null 2>&1 then eval $cmd +elif test -f "$dir/node_modules/@arkweid/lefthook/bin/lefthook" +then + eval $dir/node_modules/@arkweid/lefthook/bin/$cmd elif bundle exec lefthook -h >/dev/null 2>&1 then bundle exec $cmd