Skip to content

Instantly share code, notes, and snippets.

@chakrit
Created February 8, 2013 06:43
Show Gist options
  • Save chakrit/4737131 to your computer and use it in GitHub Desktop.
Save chakrit/4737131 to your computer and use it in GitHub Desktop.
# nvmcp $old_version
#
# Copy all globally-installed npm packages from $old_version to `default` version.
# Had to roll this since nvm copy-packages doesn't quite work.
nvmcp () {
nvm use $1
npm ls -g --parseable 2> /dev/null \
| grep -E "node_modules" \
| grep -Ev "node_modules.+node_modules" \
| sed -Ele "s/^.+node_modules\/(.+)/\\1/g" \
> /tmp/nvmx_modules
echo "Found these packages:"
cat /tmp/nvmx_modules
nvm use default
npm install -g `cat /tmp/nvmx_modules`
rm /tmp/nvmx_modules
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment