Skip to content

Commit

Permalink
Use native node if ver>=6
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Weigel committed Jan 28, 2019
1 parent 12efada commit 1b2bd5e
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions hapi-server
@@ -1,14 +1,29 @@
#!/bin/sh

# https://unix.stackexchange.com/a/76518
versionmin="v6.0.0"

# From https://unix.stackexchange.com/a/76518
path=$(exec 2>/dev/null;cd -- $(dirname "$0"); unset PWD; /usr/bin/pwd || /bin/pwd || pwd)

if command -v $path"/bin/node" > /dev/null 2>&1; then
$path"/bin/node" $path"/server.js" $@
elif command -v node > /dev/null 2>&1; then
node $path"/server.js" $@
# Use node in path if version > versionmin
if command -v node > /dev/null 2>&1; then
version=$(node -v)
if [[ $version > $versionmin ]]; then
node $path"/server.js" $@
exit 0
fi
elif command -v nodejs > /dev/null 2>&1; then
nodejs $path"/server.js" $@
version=$(nodejs -v)
if [[ $version > $versionmin ]]; then
nodejs $path"/server.js" $@
exit 0
fi
fi

# Use node in package
if command -v path"/bin/node" > /dev/null 2>&1; then
path"/bin/node" $path"/server.js" $@
else
echo "Did not find "$(dirname "$SCRIPT")"/bin/node, node, or nodejs"
exit 1
fi

0 comments on commit 1b2bd5e

Please sign in to comment.