#!/bin/sh
# script/fmt: format this repo's markdown and CSS with prettier, using
# our standard settings. Scope is every markdown and CSS file in the
# tree, per REPO_POLICIES.md ("prettier for JS/CSS/Markdown/HTML").
# What is deliberately NOT covered is recorded in .prettierignore, with
# the reason next to each entry: the Hugo layout templates, which are
# Go templates and not HTML, and content/, whose reformatting was
# measured to change the rendered page.
#
# This runs on the host, unlike the read-only check: it rewrites the
# working tree, which a container build cannot do. It is therefore the
# authoritative copy of the prettier version, scope and flags -- the
# fmt-check stage of Dockerfile.lint duplicates them and must be kept in
# sync with this file.
set -eu

ROOT="$(cd "$(dirname "$0")/.." && pwd -P)"

PRETTIER_VERSION="3.4.2"

main() {
    cd "$ROOT"
    npx --yes "prettier@${PRETTIER_VERSION}" --write \
        '**/*.md' '**/*.css' --tab-width 4 --prose-wrap always
}

main "$@"
