-
-
Save ironprogrammer/70a4fd7b15729d54becd8632f103f61f to your computer and use it in GitHub Desktop.
Calypso AnyBar handler
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 | |
| PORT="${PORT:-1738}" | |
| DONE_COLOR="${DONE_COLOR:-"black"}" | |
| PROGRESS_COLOR="${PROGRESS_COLOR:-"white"}" | |
| INITIAL_COLOR="${INITIAL_COLOR:-"white"}" | |
| BUILD_ERROR_COLOR="${BUILD_ERROR_COLOR:-"red"}" | |
| TEST_ERROR_COLOR="${TEST_ERROR_COLOR:-"purple"}" | |
| HAS_ERROR=0 | |
| main() { | |
| reset_icon | |
| tee >(update_status) | |
| } | |
| update_status() { | |
| while read line | |
| do | |
| if [[ "$line" =~ "webpack: Compiled successfully." ]]; then | |
| if [ $HAS_ERROR -eq 0 ]; then | |
| set_icon "$DONE_COLOR" | |
| else | |
| set_icon "$BUILD_ERROR_COLOR" | |
| fi | |
| elif [[ "$line" =~ "webpack: Compiling..." ]]; then | |
| HAS_ERROR=0 | |
| set_icon "$PROGRESS_COLOR" | |
| elif [[ "$line" =~ "ERROR" ]]; then | |
| HAS_ERROR=1 | |
| # for `npm run test-client:watch` | |
| elif [[ "$line" =~ "restarting due to changes" ]]; then | |
| reset_icon | |
| # for both test-client and test-client:watch | |
| elif [[ "$line" =~ "app crashed" ]] || [[ "$line" =~ ^[0-9]+\ failing$ ]]; then | |
| set_icon "$TEST_ERROR_COLOR" | |
| fi | |
| done | |
| } | |
| set_icon() { | |
| echo -n "$1" | nc -4u -w0 localhost $PORT | |
| } | |
| reset_icon() { | |
| if [ "$INITIAL_COLOR" != "" ] && [ "$INITIAL_COLOR" != "none" ]; then | |
| set_icon "$INITIAL_COLOR" | |
| fi | |
| } | |
| main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment