Philipp Schrader | ace0884 | 2022-03-26 14:52:55 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | # --- begin runfiles.bash initialization v2 --- |
| 4 | # Copy-pasted from the Bazel Bash runfiles library v2. |
| 5 | set -uo pipefail; f=bazel_tools/tools/bash/runfiles/runfiles.bash |
| 6 | source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \ |
| 7 | source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null || \ |
| 8 | source "$0.runfiles/$f" 2>/dev/null || \ |
| 9 | source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ |
| 10 | source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ |
| 11 | { echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e |
| 12 | # --- end runfiles.bash initialization v2 --- |
| 13 | |
Philipp Schrader | 817cce3 | 2022-03-26 15:00:00 -0700 | [diff] [blame] | 14 | # The rules_nodejs runfiles discovery needs some help. |
| 15 | runfiles_export_envvars |
| 16 | export RUNFILES="${RUNFILES_DIR}" |
| 17 | |
Philipp Schrader | 175a93c | 2023-02-19 13:13:40 -0800 | [diff] [blame] | 18 | PRETTIER="$(rlocation org_frc971/tools/lint/prettier_binary.sh)" |
Philipp Schrader | ace0884 | 2022-03-26 14:52:55 -0700 | [diff] [blame] | 19 | PRETTIER="$(readlink -f "${PRETTIER}")" |
| 20 | readonly PRETTIER |
| 21 | |
| 22 | # Find the files to format at the root of the repo. For some reason, the |
| 23 | # prettier binary (probably because of the rules_nodejs wrapper), breaks when |
| 24 | # invoked from a directory outside of the runfiles tree. |
| 25 | pushd "${BUILD_WORKSPACE_DIRECTORY}" |
| 26 | |
| 27 | # Find web-related files in the repo. |
| 28 | # TODO(phil): Support more than just //scouting. |
| 29 | web_files=($(git ls-tree --name-only --full-tree -r @ \ |
| 30 | | grep '^scouting/' \ |
Philipp Schrader | 3d7dedc | 2024-03-16 16:27:25 -0700 | [diff] [blame] | 31 | | grep -v '\.jinja2\.' \ |
Philipp Schrader | ace0884 | 2022-03-26 14:52:55 -0700 | [diff] [blame] | 32 | | (grep \ |
| 33 | -e '\.ts$' \ |
| 34 | -e '\.js$' \ |
| 35 | -e '\.css$' \ |
| 36 | -e '\.html$' \ |
| 37 | || :))) |
| 38 | |
| 39 | web_files_abs_paths=($(for file in "${web_files[@]}"; do |
| 40 | readlink -f "${file}" |
| 41 | done)) |
| 42 | |
| 43 | CONFIG_FILE="$(readlink -f .prettierrc.json)" |
| 44 | readonly CONFIG_FILE |
| 45 | |
| 46 | # Go back to the runfiles directory so that prettier doesn't break. |
| 47 | popd |
| 48 | |
| 49 | # If we have any web-related files, format them. |
| 50 | if ((${#web_files_abs_paths[@]} > 0)); then |
| 51 | "${PRETTIER}" \ |
| 52 | --config "${CONFIG_FILE}" \ |
| 53 | --write \ |
| 54 | "${web_files_abs_paths[@]}" |
| 55 | fi |