Created
October 21, 2017 23:01
-
-
Save clamstew/491cbdf3515ee7cb5dedc1540436aba0 to your computer and use it in GitHub Desktop.
A bash script to be able to run `yarn display-npm-updates` and safely run ncu (npm-check-updates) with a warning message if the user / dev does not have it installed
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/bash | |
echo 'checking for package.json updates using npmjs.com/package/npm-check-updates' >&2 | |
# define some fun output colors - https://stackoverflow.com/questions/5947742 | |
RED='\033[0;31m' | |
BLUE='\033[0;34m' | |
YELLOW='\033[1;33m' | |
GREEN='\033[0;32m' | |
NC='\033[0m' # No Color | |
# check if user has ncu installed | |
if ! [ -x "$(command -v ncu)" ]; then | |
# kindly prompt them that, we'd like the developer to install npm-check-updates | |
echo '' >&2 | |
echo -e "${BLUE}===================================================================================${NC}" >&2 | |
echo -e "${YELLOW}Warning:${NC} ${GREEN}``ncu`` (npm-check-updates)${NC} is not installed." >&2 | |
echo '' >&2 | |
echo 'This is useful for keeping this project up to date.' >&2 | |
echo '' >&2 | |
echo -e "Please run, ${RED}``yarn global add npm-check-updates``${NC}," >&2 | |
echo 'so we can display available npm updates during local CRA development scripts.' >&2 | |
echo '' >&2 | |
echo '(if you are seeing this on CI, then make sure to install ``ncu`` on the base image:' >&2 | |
echo ' BASE_IMAGE)' >&2 | |
echo -e "${BLUE}===================================================================================${NC}" >&2 | |
echo '' >&2 | |
else | |
# run the check of package.json dependencies | |
ncu | |
fi | |
# exit gracefully | |
exit 0 |
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
{ | |
"scripts": { | |
"display-npm-updates": "npm-check-updates.sh" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
would run
chmod u+x npm-check-updates.sh
to make this executable (https://stackoverflow.com/questions/8779951)