Skip to content

Instantly share code, notes, and snippets.

@JakeSidSmith
Last active July 13, 2018 09:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JakeSidSmith/0ddc45b08cacc8152492ba8f2598345b to your computer and use it in GitHub Desktop.
Save JakeSidSmith/0ddc45b08cacc8152492ba8f2598345b to your computer and use it in GitHub Desktop.
Find bad version of eslint-scope in global node_modules, nvm dir, trash, and current directory.
#!/usr/bin/env bash
set -e
PACKAGE_NAME="eslint-scope"
PACKAGE_VERSION="3.7.2"
COLOR_RED="[1;31m"
COLOR_GREEN="[1;32m"
COLOR_YELLOW="[1;33m"
COLOR_NONE="[1;39m"
ESC="$(printf '\033')"
function check_packages {
find $1 -wholename "**/$2/package.json" | while read LINE; do
VERSION="$(echo $LINE | xargs cat | grep '"version":')"
if [[ $VERSION = *$3* ]]; then
echo "${ESC}${COLOR_RED}WARNING: Found $1 version $3 at '${LINE}'${ESC}${COLOR_NONE}"
else
echo "${ESC}${COLOR_GREEN}︎︎✔︎${ESC}${COLOR_NONE}"
fi
done
}
function find_bad_module {
PACK="${ESC}${COLOR_YELLOW}$2${ESC}${COLOR_NONE}"
VER="${ESC}${COLOR_YELLOW}$3${ESC}${COLOR_NONE}"
DIR="${ESC}${COLOR_YELLOW}$1${ESC}${COLOR_NONE}"
echo "Checking for ${PACK} version ${VER} in ${DIR}"
echo "..."
check_packages $1 $2 $3
echo "${ESC}${COLOR_GREEN}Done${ESC}${COLOR_NONE}"
echo ""
}
find_bad_module "/usr/local/lib/node_modules" $PACKAGE_NAME $PACKAGE_VERSION
find_bad_module "/usr/local/lib/node" $PACKAGE_NAME $PACKAGE_VERSION
find_bad_module $NVM_DIR $PACKAGE_NAME $PACKAGE_VERSION
find_bad_module "$HOME/.Trash/" $PACKAGE_NAME $PACKAGE_VERSION
find_bad_module "$HOME/.local/share/Trash" $PACKAGE_NAME $PACKAGE_VERSION
find_bad_module "./" $PACKAGE_NAME $PACKAGE_VERSION
# echo $RESULT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment