blob: ef4f5cad8165f7e3d77bb703f4a356958d53b319 [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
Philipp Schrader817cce32022-03-26 15:00:00 -070014# The rules_nodejs runfiles discovery needs some help.
15runfiles_export_envvars
16export RUNFILES="${RUNFILES_DIR}"
17
Philipp Schrader175a93c2023-02-19 13:13:40 -080018PRETTIER="$(rlocation org_frc971/tools/lint/prettier_binary.sh)"
Philipp Schraderace08842022-03-26 14:52:55 -070019PRETTIER="$(readlink -f "${PRETTIER}")"
20readonly 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.
25pushd "${BUILD_WORKSPACE_DIRECTORY}"
26
27# Find web-related files in the repo.
28# TODO(phil): Support more than just //scouting.
29web_files=($(git ls-tree --name-only --full-tree -r @ \
30 | grep '^scouting/' \
Philipp Schrader3d7dedc2024-03-16 16:27:25 -070031 | grep -v '\.jinja2\.' \
Philipp Schraderace08842022-03-26 14:52:55 -070032 | (grep \
33 -e '\.ts$' \
34 -e '\.js$' \
35 -e '\.css$' \
36 -e '\.html$' \
37 || :)))
38
39web_files_abs_paths=($(for file in "${web_files[@]}"; do
40 readlink -f "${file}"
41done))
42
43CONFIG_FILE="$(readlink -f .prettierrc.json)"
44readonly CONFIG_FILE
45
46# Go back to the runfiles directory so that prettier doesn't break.
47popd
48
49# If we have any web-related files, format them.
50if ((${#web_files_abs_paths[@]} > 0)); then
51 "${PRETTIER}" \
52 --config "${CONFIG_FILE}" \
53 --write \
54 "${web_files_abs_paths[@]}"
55fi