blob: dc295222458b9ff7283da493fd1f558b07efd54d [file] [log] [blame]
Philipp Schraderace08842022-03-26 14:52:55 -07001#!/bin/bash
2
3# --- begin runfiles.bash initialization v2 ---
4# Copy-pasted from the Bazel Bash runfiles library v2.
5set -uo pipefail; f=bazel_tools/tools/bash/runfiles/runfiles.bash
6source "${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
14PRETTIER="$(rlocation npm/prettier/bin/prettier.sh)"
15PRETTIER="$(readlink -f "${PRETTIER}")"
16readonly PRETTIER
17
18# Find the files to format at the root of the repo. For some reason, the
19# prettier binary (probably because of the rules_nodejs wrapper), breaks when
20# invoked from a directory outside of the runfiles tree.
21pushd "${BUILD_WORKSPACE_DIRECTORY}"
22
23# Find web-related files in the repo.
24# TODO(phil): Support more than just //scouting.
25web_files=($(git ls-tree --name-only --full-tree -r @ \
26 | grep '^scouting/' \
27 | (grep \
28 -e '\.ts$' \
29 -e '\.js$' \
30 -e '\.css$' \
31 -e '\.html$' \
32 || :)))
33
34web_files_abs_paths=($(for file in "${web_files[@]}"; do
35 readlink -f "${file}"
36done))
37
38CONFIG_FILE="$(readlink -f .prettierrc.json)"
39readonly CONFIG_FILE
40
41# Go back to the runfiles directory so that prettier doesn't break.
42popd
43
44# If we have any web-related files, format them.
45if ((${#web_files_abs_paths[@]} > 0)); then
46 "${PRETTIER}" \
47 --config "${CONFIG_FILE}" \
48 --write \
49 "${web_files_abs_paths[@]}"
50fi