Skip to content

Instantly share code, notes, and snippets.

@nexdrew
Forked from soldair/republish.sh
Last active November 29, 2016 15:56
Show Gist options
  • Select an option

  • Save nexdrew/9b198381a9eb2eca407e658be860edfe to your computer and use it in GitHub Desktop.

Select an option

Save nexdrew/9b198381a9eb2eca407e658be860edfe to your computer and use it in GitHub Desktop.
publish modules from the public registry to another registry
#!/bin/bash
mkdir -p ./publish-tmp
cd publish-tmp
if [ "$?" != "0" ]; then
echo "failed to create publish tmp dir"
exit 1
fi
NPMTOKEN=`grep ^//registry.npmjs.org/:_authToken= ~/.npmrc | sed 's/_authToken=/ /' | awk '{print $2}'`
registry="http://registry.npm.red"
modulename=`echo "$1" | sed 's/\//%2f/'`
json=`curl https://registry.npmjs.org/$modulename 2> /dev/null`
if [ "$?" != "0" ]; then
echo "failed to download module $modulename" 2>1
exit $?
fi
tars=`echo $json | json_pp | grep tarball | sed 's/[",]//g' | awk '{print $3}'`
download(){
echo "downloading "$1
curl -H "Authorization: Bearer $NPMTOKEN" "$1" > tartmp.tgz
if [ "$?" != "0" ]; then
echo "failed to download tar $1" 2>1
exit $?
fi
tar -xvf tartmp.tgz
cd package
echo "npm publish --registry $registry"
rm -fr package
}
for tar in $tars;
do
download $tar
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment