-
-
Save soldair/e4c34dd0f2d3b7a775c0ba934b9235ac to your computer and use it in GitHub Desktop.
publish modules from the publish registry to another registry
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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}'` | |
reallyPublish="$3" | |
registry="$2" | |
modulename=`echo "$1" | sed 's/\//%2f/'` | |
helptext="usage: ./republish.sh [module name] [target registry] [--really-publish] example: ./republish.sh lodash https://npme.mycompany.com # without the --really-publish this performs a dry run." | |
if [ "$registry" == "" ]; then | |
echo $helptext | |
exit 1 | |
fi | |
if [ "$modulename" == "" ]; then | |
echo $helptext | |
exit 1 | |
fi | |
echo "republishing all versions of $modulename to registry $registry" | |
tars=`curl -H "Authorization: Bearer $NPMTOKEN" https://registry.npmjs.org/$modulename 2> /dev/null | \ | |
node -e "s='';process.stdin.on('data',function(b){s += b}).on('end',function(){ process.stdout.write(JSON.stringify(JSON.parse(s),null,' ')+'\n')})" | \ | |
grep tarball | sed 's/[",]//g' | awk '{print $2}'` | |
if [ "$?" != "0" ]; then | |
echo "failed to download module $modulename" 2>1 | |
exit $? | |
fi | |
download(){ | |
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 "preparing to publish "$1 | |
if [ "$reallyPublish" == "--really-publish" ]; then | |
npm publish --registry $registry | |
else | |
echo "DRY RUN" | |
echo "npm publish --registry $registry" | |
fi | |
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