Skip to content

Instantly share code, notes, and snippets.

@Rob--W
Created December 9, 2015 11:40
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 Rob--W/56cff1b191b23b860118 to your computer and use it in GitHub Desktop.
Save Rob--W/56cff1b191b23b860118 to your computer and use it in GitHub Desktop.
Downloads and extracts specific npm package without dependencies or hooks.
#!/bin/bash
# Downloads and extracts specific npm package without dependencies or hooks.
# Usage:
# npm-download-only [package1] [package2] ...
# where package can be a specific version (e.g. package@1.0.0) or package.
#
# Written on 9 dec 2015 by Rob Wu (https://robwu.nl)
for arg in "$@"
do
if [ -e "$arg" ] ; then
echo "$arg exists already -- skipping."
continue
fi
tarball=$(npm view "$arg" dist.tarball)
if [ -z "$tarball" ] ; then
echo "No dist.tarball found for '$arg'"
continue
fi
if ! mkdir "$arg" ; then
echo "Failed to create directory '$arg'"
continue
fi
echo "Downloading '$tarball' and extracting it to '$arg'"
curl "$tarball" | tar xz --strip-components 1 --directory "$arg"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment