| Philip Zeyliger | 8b00db1 | 2025-04-25 18:41:38 +0000 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | set -e |
| 3 | |
| 4 | # Script to run formatters for both Go and webui files |
| 5 | # Usage: bin/run-formatters.sh [check] |
| 6 | # If 'check' is provided, only checks formatting without making changes |
| 7 | |
| 8 | CHECK_MODE=false |
| 9 | if [ "$1" = "check" ]; then |
| 10 | CHECK_MODE=true |
| 11 | echo "Running in check mode (formatting will not be modified)" |
| 12 | else |
| 13 | echo "Running in fix mode (formatting will be modified)" |
| 14 | fi |
| 15 | |
| 16 | # Go formatting with gofumpt |
| 17 | echo "Checking Go formatting..." |
| 18 | if [ "$CHECK_MODE" = true ]; then |
| 19 | # In check mode, we want to display the files that need formatting and exit with error if any |
| 20 | FILES_TO_FORMAT=$(gofumpt -l .) |
| 21 | if [ -n "$FILES_TO_FORMAT" ]; then |
| 22 | echo "The following Go files need formatting:" |
| 23 | echo "$FILES_TO_FORMAT" |
| 24 | exit 1 |
| 25 | else |
| 26 | echo "Go formatting check passed" |
| 27 | fi |
| 28 | else |
| 29 | # In fix mode, we apply the formatting |
| 30 | echo "Fixing Go formatting with gofumpt" |
| 31 | gofumpt -w . |
| 32 | echo "Go formatting complete" |
| 33 | fi |
| 34 | |
| 35 | # Webui formatting with Prettier |
| 36 | echo "Checking webui formatting..." |
| 37 | if [ -d "./webui" ]; then |
| 38 | cd webui |
| 39 | if [ "$CHECK_MODE" = true ]; then |
| 40 | echo "Checking webui formatting with Prettier" |
| 41 | if ! npx prettier --check .; then |
| 42 | echo "Webui files need formatting" |
| 43 | exit 1 |
| 44 | fi |
| 45 | else |
| 46 | echo "Fixing webui formatting with Prettier" |
| 47 | npx prettier --write . |
| 48 | echo "Webui formatting complete" |
| 49 | fi |
| 50 | else |
| 51 | echo "No webui directory found, skipping Prettier check" |
| 52 | fi |
| 53 | |
| 54 | if [ "$CHECK_MODE" = true ]; then |
| 55 | echo "All formatting checks passed" |
| 56 | else |
| 57 | echo "All formatting has been fixed" |
| 58 | fi |