Skip to content

Instantly share code, notes, and snippets.

@shaunmolloy
Last active August 5, 2022 14:02
Show Gist options
  • Save shaunmolloy/ce6ad16282cdd37e817d234afb0dd79b to your computer and use it in GitHub Desktop.
Save shaunmolloy/ce6ad16282cdd37e817d234afb0dd79b to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# time-npm-start
URL="http://localhost:3000/"
spinner() {
I=$(( (I+1) %4 ))
printf "\r${SPIN:$I:1} $1"
}
loaded() {
if $(curl -s -m 0.1 $URL | grep -q "</html>"); then
LOADED=true
fi
}
START=$(date +%s)
LOADED=false
SPIN='-\|/'
I=0
# Start dev server
npm run start > /dev/null 2>&1 &
while ! "$LOADED" ; do
spinner "Starting server..."
loaded
sleep 0.1
done
END=$(date +%s)
# Kill dev server
pkill -9 -f node 2> /dev/null
echo -e "Server killed\n"
echo "Time started: $(date +"%Y-%m-%d %H:%M:%S" -d @$START)"
echo -e "Time completed: $(date +"%Y-%m-%d %H:%M:%S" -d @$END)\n"
SECONDS=$((END-START))
echo "Duration in seconds: ${SECONDS}s"
if [ $SECONDS -ge 60 ]; then
MINUTES=$(echo "scale=1; $SECONDS/60" | bc -l)
echo "Duration in minutes: ${MINUTES}m"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment