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.

Revisions

  1. nexdrew revised this gist Nov 29, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion republish.sh
    Original file line number Diff line number Diff line change
    @@ -43,7 +43,7 @@ fi

    download(){

    curl -H "Authorization: Bearer $NPMTOKEN" "$1" > tartmp.tgz
    curl -H "Authorization: Bearer $NPMTOKEN" "$1" > tartmp.tgz 2> /dev/null
    if [ "$?" != "0" ]; then
    echo "failed to download tar $1" 2>1
    exit $?
  2. @soldair soldair revised this gist Nov 29, 2016. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions republish.sh
    Original file line number Diff line number Diff line change
    @@ -31,7 +31,7 @@ fi
    echo "republishing all versions of $modulename to registry $registry"


    tars=`curl https://registry.npmjs.org/$modulename 2> /dev/null | \
    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}'`

    @@ -43,7 +43,7 @@ fi

    download(){

    curl -H "Bearer: $NPMTOKEN" "$1" > tartmp.tgz
    curl -H "Authorization: Bearer $NPMTOKEN" "$1" > tartmp.tgz
    if [ "$?" != "0" ]; then
    echo "failed to download tar $1" 2>1
    exit $?
  3. @soldair soldair revised this gist Nov 29, 2016. 1 changed file with 33 additions and 8 deletions.
    41 changes: 33 additions & 8 deletions republish.sh
    Original file line number Diff line number Diff line change
    @@ -10,22 +10,40 @@ fi

    NPMTOKEN=`grep ^//registry.npmjs.org/:_authToken= ~/.npmrc | sed 's/_authToken=/ /' | awk '{print $2}'`

    registry="http://registry.npm.red"

    reallyPublish="$3"
    registry="$2"
    modulename=`echo "$1" | sed 's/\//%2f/'`

    json=`curl https://registry.npmjs.org/$modulename 2> /dev/null`
    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 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

    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

    curl -H "Bearer: $NPMTOKEN" "$1" > tartmp.tgz
    if [ "$?" != "0" ]; then
    echo "failed to download tar $1" 2>1
    exit $?
    @@ -34,11 +52,18 @@ download(){

    tar -xvf tartmp.tgz
    cd package
    npm publish --registry $registry

    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
    done
  4. @soldair soldair revised this gist Nov 29, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion republish.sh
    Original file line number Diff line number Diff line change
    @@ -34,7 +34,7 @@ download(){

    tar -xvf tartmp.tgz
    cd package
    echo "npm publish --registry $registry"
    npm publish --registry $registry
    rm -fr package
    }

  5. @soldair soldair revised this gist Nov 29, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion republish.sh
    Original file line number Diff line number Diff line change
    @@ -25,7 +25,7 @@ tars=`echo $json | json_pp | grep tarball | sed 's/[",]//g' | awk '{print $3}'`

    download(){
    echo "downloading "$1
    curl -H "Bearer: $NPMTOKEN" "$1" > tartmp.tgz
    curl -H "Authorization: Bearer $NPMTOKEN" "$1" > tartmp.tgz
    if [ "$?" != "0" ]; then
    echo "failed to download tar $1" 2>1
    exit $?
  6. @soldair soldair created this gist Nov 29, 2016.
    44 changes: 44 additions & 0 deletions republish.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,44 @@
    #!/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 "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