Skip to content

Commit

Permalink
Merge pull request #146 from nesk/npm-optimization
Browse files Browse the repository at this point in the history
Improve performance with NPM package
  • Loading branch information
Abroskin Alexander authored Sep 8, 2020
2 parents 278315f + b742f15 commit e141b9a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 22 deletions.
31 changes: 9 additions & 22 deletions .npm/bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
13 changes: 13 additions & 0 deletions .npm/bin/lefthook
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions cmd/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e141b9a

Please sign in to comment.