Skip to content

Instantly share code, notes, and snippets.

@ttyS0
Created May 24, 2019 18:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ttyS0/345925677edfcd9194b7d2e9866eef1b to your computer and use it in GitHub Desktop.
Save ttyS0/345925677edfcd9194b7d2e9866eef1b to your computer and use it in GitHub Desktop.
BoxCLI Builder
#!/usr/bin/env bash
NODE_REQUIRED="v10"
# True if $1 is an executable in $PATH
function is_bin_in_path {
builtin type -P "$1" &> /dev/null
}
# check for node
if is_bin_in_path node; then
NODE_VERSION=$(node --version | cut -d\. -f1)
if [[ ${NODE_VERSION} != ${NODE_REQUIRED} ]]; then
echo "Node ${NODE_REQUIRED} is required! Node ${NODE_VERSION} is installed!"
exit 1
fi
else
echo "Node isn't installed, or not in your path!"
fi
# if git is installed, and this is a git repo, update the repo
if is_bin_in_path git; then
if git rev-parse --is-inside-work-tree &> /dev/null; then
echo "Updating Git Repository..."
git pull
else
echo "WARN: this isn't a git repository, problems may result"
fi
else
echo "WARN: this isn't a git repository, problems may result"
fi
# run npm install & npm install -g pkg
echo "Updating npm packages..."
npm install
npm install -g pkg
# build binaries
if is_bin_in_path pkg; then
echo "Installing binaries to pkg directory..."
for arch in macos linux win
do
echo -n "building boxcli-$arch..."
pkg -o pkg/boxcli-$arch -t node10-$arch-x64 .
# compress if possible
if is_bin_in_path zip; then
echo -n "compressing boxcli-$arch"
if [[ $arch == "win" ]]; then
mv pkg/boxcli-$arch.exe pkg/boxcli.exe
zip -j pkg/boxcli-$arch.zip pkg/boxcli.exe
rm pkg/boxcli.exe
else
mv pkg/boxcli-$arch pkg/boxcli
zip -j pkg/boxcli-$arch.zip pkg/boxcli
rm pkg/boxcli
fi
fi
done
echo "Done!"
exit 0
else
echo "Node 'pkg' command is not available!"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment