Skip to content

Instantly share code, notes, and snippets.

@klamping
Created July 23, 2015 19:28
Show Gist options
  • Save klamping/92c30af11d203e24238a to your computer and use it in GitHub Desktop.
Save klamping/92c30af11d203e24238a to your computer and use it in GitHub Desktop.
NPM preinstall for private registries behind VPNs
{
"name": "myApp",
"version": "1.0.0",
"scripts": {
"preinstall": "sh vpn-check.sh"
},
"dependencies": {
"moduleOnPrivateRepo": "1.0.0"
}
}
#!/bin/bash
# Because you need to be on the VPN to connect to the private NPM Registry,
# this script checks for that before running `npm install`.
# This helps prevent developer confusion when they're not connected to the VPN
# and `npm install` hangs when trying to find the registry server
# If the ping fails, NPM quits the install and hopefully the dev reads the error message
echo 'Checking if you are connected to the VPN'
ping -c 1 -W 10 your.ip.address.here &> /dev/null
if [ $? -ne 0 ]
then
echo '\n-----\nERROR: You need to be connected to the VPN to run npm install.\n-----'
exit 1
else
echo 'You are connected. Continuing with install.'
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment