#!/bin/bash
if [[ $# -eq 0 ]] ; then
echo "Usage: $0 jquery bootstrap@3 tinymce@4.5"
exit 64 ## EX_USAGE
fi
set -e ## So nothing gets deleted if download fails
for pkg_name in "$@"
do
## Get latest version, also works with plain name
url=$( npm v $pkg_name dist.tarball | tail -n 1 | cut -d \' -f 2 )
tmp_dir=$( mktemp -d -p . "${pkg_name}__XXXXXXXXX" )
## Unpacks to directory named after package@version
curl $url | tar -xzf - --strip 1 --directory $tmp_dir
rm -rf $pkg_name
mv $tmp_dir $pkg_name
done