-
-
Notifications
You must be signed in to change notification settings - Fork 660
Expand file tree
/
Copy pathcheck-formatting.sh
More file actions
executable file
·50 lines (45 loc) · 2.24 KB
/
check-formatting.sh
File metadata and controls
executable file
·50 lines (45 loc) · 2.24 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env bash
set -uo pipefail
if [ -z "${EXERCISM_PRETTIER_VERSION:-}" ]; then
echo "[format] pulling prettier version from pnpm list using sed"
EXERCISM_PRETTIER_VERSION="$(corepack pnpm list prettier --parseable | sed -n -e '1,$s/^.*prettier@//' -e 's/\\node_modules\\prettier//p')"
echo "[format] expected version is now ${EXERCISM_PRETTIER_VERSION:-}"
fi
if [ -z "${EXERCISM_PRETTIER_VERSION:-}" ]; then
echo "[format] pulling prettier version via pnpm-lock.yaml using grep"
EXERCISM_PRETTIER_VERSION="$(cat pnpm-lock.yaml | grep -Po ' prettier@\K[^:]+')"
echo "[format] expected version is now ${EXERCISM_PRETTIER_VERSION:-}"
fi
if [ -z "${EXERCISM_PRETTIER_VERSION:-}" ]; then
echo "Version could not be pulled using sed or grep" >&2
echo ""
echo "---------------------------------------------------"
echo "This script requires the EXERCISM_PRETTIER_VERSION variable to work."
echo "Please see https://exercism.org/docs/building/markdown/style-guide for guidance."
echo "---------------------------------------------------"
echo "$(corepack pnpm -v)"
echo ""
echo "This is what corepack pnpm list reports:"
echo "$ corepack pnpm list prettier --parseable"
echo "$(corepack pnpm list prettier --parseable)"
echo ""
echo "And corepack pnpm info reports the following:"
echo "$ corepack pnpm info prettier"
echo "$(corepack pnpm info prettier)"
echo ""
echo "This is the version that can be extracted using sed:"
echo "$ corepack pnpm list prettier --parseable | sed -n -e '1,\$s/^.*prettier@//' -e 's/\\node_modules\\prettier//p'"
echo "└─ $(corepack pnpm list prettier --parseable | sed -n -e '1,$s/^.*prettier@//' -e 's/\\node_modules\\prettier//p')"
echo ""
echo "This is the version that can be extracted using grep:"
echo "$ cat pnpm-lock.yaml | grep -Po ' prettier@\K[^:]+'"
echo "└─ $(cat pnpm-lock.yaml | grep -Po ' prettier@\K[^:]+')"
echo ""
echo "These files are found in the repo root:"
echo "$(ls -p | grep -v /)"
echo "---------------------------------------------------"
exit 1
else
echo "[format] running with prettier@$EXERCISM_PRETTIER_VERSION"
fi
corepack pnpm dlx "prettier@$EXERCISM_PRETTIER_VERSION" --check "**/*.{js,jsx,cjs,mjs,ts,tsx,css,sass,scss,html,json,md,yml}"