Skip to content

Instantly share code, notes, and snippets.

@erickmerchant
Last active March 27, 2022 18:07
Show Gist options
  • Save erickmerchant/913a138970c8a0bebf4b480fa502018d to your computer and use it in GitHub Desktop.
Save erickmerchant/913a138970c8a0bebf4b480fa502018d to your computer and use it in GitHub Desktop.
a bash script I use to run npm audit, npm outdated, npm test, and git status on all my projects
BOLD='\033[1m'
RESET='\033[0m'
COLS=$(expr $(tput cols) - 4)
if [ $# -eq 0 ]
then
DIRECTORIES=*/;
else
DIRECTORIES=$@;
fi
for d in $DIRECTORIES;
do (
cd $d;
if [ $? -eq 0 ]
then
echo $BOLD'# '$d$RESET;
if test -f "package-lock.json"
then
OUTPUT=$(npm update --parseable)
RESULT=$?
if [ $RESULT -gt 0 ]
then
echo $BOLD' audit: '$RESET;
echo $OUTPUT | xargs | fold -w $COLS | sed 's/^/ /';
fi
OUTPUT=$(npm outdated --parseable)
RESULT=$?
if [ -n "$OUTPUT" ]
then
echo $BOLD' outdated: '$RESET;
echo $OUTPUT | xargs | fold -w $COLS | sed 's/^/ /';
fi
OUTPUT=$(npm run --if-present --silent test)
RESULT=$?
if [ $RESULT -gt 0 ]
then
echo $BOLD' test: '$RESET;
echo $OUTPUT | xargs | fold -w $COLS | sed 's/^/ /';
fi
fi
if test -f "Cargo.lock"
then
cargo update -q;
OUTPUT=$(cargo outdated --depth=1 --exit-code=1)
RESULT=$?
if [ $RESULT -gt 0 ]
then
echo $BOLD' outdated: '$RESET;
echo $OUTPUT | xargs | fold -w $COLS | sed 's/^/ /';
fi
fi
OUTPUT=$(git status --porcelain | xargs)
if [ -n "$OUTPUT" ]
then
echo $BOLD' status: '$RESET;
echo $OUTPUT | fold -w $COLS | sed 's/^/ /';
fi
fi
)
done;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment