#!/bin/sh
# script/fmt: format all files (writes). gofmt for Go, prettier for
# Markdown. prettier is the pinned devDependency in package.json/
# yarn.lock; script/bootstrap installs it (see run_prettier).
set -eu

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

run_prettier() {
    if ! command -v yarn >/dev/null 2>&1; then
        echo "fmt: yarn not found; run script/bootstrap first" >&2
        exit 1
    fi
    yarn run prettier "$@"
}

main() {
    cd "$ROOT"
    gofmt -s -w .
    run_prettier --write '**/*.md' --tab-width 4 --prose-wrap always
}

main "$@"
