-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathformatter.sh
More file actions
33 lines (26 loc) · 1.11 KB
/
Copy pathformatter.sh
File metadata and controls
33 lines (26 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/env bash
set -euo pipefail
echo "formatter.sh: running Prettier to beautify project files"
ROOT_DIR="$(cd "$(dirname "$0")" && pwd)"
cd "$ROOT_DIR"
if [ -x "node_modules/.bin/prettier" ]; then
PRETTIER_CMD="./node_modules/.bin/prettier"
else
PRETTIER_CMD="npx prettier"
fi
echo "Using: $PRETTIER_CMD"
TARGET_PATTERNS=("api/**/*.{ts,tsx,js,json,html,css,md}" "app/**/*.{ts,tsx,js,html,css,md}" "*.ts" "*.js" "*.html" "*.css")
shopt -s globstar nullglob || true
mapfile -d '' -t FILES < <(find api app -type f \( -name "*.ts" -o -name "*.tsx" -o -name "*.js" -o -name "*.json" -o -name "*.html" -o -name "*.css" -o -name "*.md" \) -not -path "*/node_modules/*" -not -path "*/resources/*" -print0 2>/dev/null || true)
if [ ${#FILES[@]} -eq 0 ]; then
echo "No target files found for formatting."
exit 0
fi
echo "Running: $PRETTIER_CMD --write ${#FILES[@]} files"
if $PRETTIER_CMD --write "${FILES[@]}" "$@"; then
echo "Prettier formatting completed successfully."
exit 0
else
echo "Prettier failed. Ensure Prettier is installed (npm install --save-dev prettier) or run via npx." >&2
exit 1
fi