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 | ace0884 | 2022-03-26 14:52:55 -0700 | [diff] [blame] | 18 | PRETTIER="$(rlocation npm/prettier/bin/prettier.sh)" |
| 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/' \ |
| 31 | | (grep \ |
| 32 | -e '\.ts$' \ |
| 33 | -e '\.js$' \ |
| 34 | -e '\.css$' \ |
| 35 | -e '\.html$' \ |
| 36 | || :))) |
| 37 | |
| 38 | web_files_abs_paths=($(for file in "${web_files[@]}"; do |
| 39 | readlink -f "${file}" |
| 40 | done)) |
| 41 | |
| 42 | CONFIG_FILE="$(readlink -f .prettierrc.json)" |
| 43 | readonly CONFIG_FILE |
| 44 | |
| 45 | # Go back to the runfiles directory so that prettier doesn't break. |
| 46 | popd |
| 47 | |
| 48 | # If we have any web-related files, format them. |
| 49 | if ((${#web_files_abs_paths[@]} > 0)); then |
| 50 | "${PRETTIER}" \ |
| 51 | --config "${CONFIG_FILE}" \ |
| 52 | --write \ |
| 53 | "${web_files_abs_paths[@]}" |
| 54 | fi |