Skip to content

Instantly share code, notes, and snippets.

@jspiro
Last active May 13, 2020 06:22
Show Gist options
  • Save jspiro/98eec0006081b29b4017dd811f40a26d to your computer and use it in GitHub Desktop.
Save jspiro/98eec0006081b29b4017dd811f40a26d to your computer and use it in GitHub Desktop.
CLI tool to log in to Artifactory NPM
#!/bin/sh
scope=company-name
any_scoped_package_name=secret_package
url=artifactory.company.com
repo=npm
cd "$(dirname "$0")" || exit
echo Please enter your email address:
read -r email
echo
echo Please enter your Artifactory API token:
read -r token
echo
echo Generating .npmrc, keep this in "$(pwd -P)"
echo
echo registry=https://$url/artifactory/api/npm/$repo/ >.npmrc
curl -u"$email:$token" https://$url/artifactory/api/$repo/auth >>.npmrc 2>/dev/null
curl -u"$email:$token" https://$url/artifactory/api/npm/$repo/auth/$scope >>.npmrc 2>/dev/null
sed -i '' -e "s!ENTER_YOUR_EMAIL_HERE!$email!" .npmrc
echo Testing...
echo
if ! npm info @$scope/$any_scoped_package_name; then
echo =====================================
echo Check your credentials and try again.
exit
fi
echo
echo ====================================================
echo Do you want to overwrite your user ~/.npmrc as well?
echo
echo You may get faster and more reliable package installation, but you will no longer
echo be able to publish packages to the original NPM Private Registry, only to Artifactory.
echo
echo Do you want to use Artifactory instead of NPM Private Registry?
echo \(Only 'yes' will be accepted\)
read -r x
[ "$x" = "yes" ] && cp .npmrc ~/.npmrc
echo Done.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment