Skip to content

Instantly share code, notes, and snippets.

@djm158
Last active November 29, 2018 20:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save djm158/94ea0b40b970b37349a6fea6afec08bc to your computer and use it in GitHub Desktop.
Save djm158/94ea0b40b970b37349a6fea6afec08bc to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
if [ $# -le 1 ]
then
echo "Usage: get-npm-install \$PACKAGE_NAME \$PACKAGE_VERSION"
exit 1
fi
PKG_NAME=$1
PKG_VERSION=$2
TARBALL_URL="$(npm view $PKG_NAME@$PKG_VERSION dist.tarball)"
TEMP_FILE=$(mktemp --quiet /tmp/XXXXXXXX)
# download npm tarball to tmp file
wget --quiet $TARBALL_URL -O $TEMP_FILE
# get sha256 hash
# sha256sum output format is $HASH $FILENAME, just get the HASH here
HASH=$(sha256sum $TEMP_FILE | cut -d " " -f 1)
# cleanup
rm $TEMP_FILE
echo "npm_install("
echo " name = '${PKG_NAME}',"
echo " version = '${PKG_VERSION}',"
echo " sha256 = '${HASH}',"
echo ")"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment