Last active
May 13, 2020 06:22
CLI tool to log in to Artifactory NPM
This file contains hidden or 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/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