Skip to content

Instantly share code, notes, and snippets.

@nexdrew
Created May 26, 2016 15:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nexdrew/8944bb8725edaaa72afa2509cd715d78 to your computer and use it in GitHub Desktop.
Save nexdrew/8944bb8725edaaa72afa2509cd715d78 to your computer and use it in GitHub Desktop.
bash script to manually publish a public package to your private npm Enterprise registry
#!/usr/bin/env bash
trap 'exit' ERR
for PACKAGE
do
echo "$PACKAGE"
# download and extract tarball for latest version
curl `npm info $PACKAGE dist.tarball --registry https://registry.npmjs.org` | tar xz
# run this script with NPME_REGISTRY=http://reg.myco.com:8080
# or make sure ~/.npmrc points to your private registry by default
if [[ "x$NPME_REGISTRY" != "x" ]]
then
npm publish package --ignore-scripts --registry $NPME_REGISTRY
else
npm publish package --ignore-scripts
fi
# cleanup extracted tarball contents
rm -rf package
done
echo "success!"
@nexdrew
Copy link
Author

nexdrew commented May 26, 2016

Here are some examples of running this script, passing the names of packages as args.

Either first point your ~/.npmrc file to your private registry by default:

npm config set registry http://registry.myco.com:8080
sh replicate-package.sh @kadira/storybook-core @kadira/storybook

Or specify the NPME_REGISTRY var when running this script:

NPME_REGISTRY=http://registry.myco.com:8080 sh replicate-package.sh @kadira/storybook-core @kadira/storybook

@jasonk
Copy link

jasonk commented Aug 15, 2019

FYI: npm can publish a tarball directly, so you can skip unpacking it just to have npm immediately pack it again. Also the npm pack command can download a package for you, and helpfully dumps the filename that it downloaded to stdout:

#!/usr/bin/env bash
set -e

for package in "$@"; do
  file="$(npm --registry=https://registry.npmjs.org pack "$package")"
  if [ -f "$file" ]; then
    npm publish "$file"
  else
    echo "Failed to download $package" 1>&2
  fi
done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment