|
1 | 1 | #!/usr/bin/env bash
|
2 | 2 |
|
3 |
| -if [ -z "$EXERCISM_PRETTIER_VERSION" ]; then |
4 |
| - echo "Pulling prettier version from package.json" |
5 |
| - EXERCISM_PRETTIER_VERSION=$(yarn list --pattern prettier | grep -Po '.*\sprettier@\K.*') |
| 3 | +set -uo pipefail |
| 4 | + |
| 5 | +if [ -z "${EXERCISM_PRETTIER_VERSION:-}" ]; then |
| 6 | + echo "[format] pulling prettier version from yarn.lock using sed" |
| 7 | + EXERCISM_PRETTIER_VERSION="$(yarn info prettier --json --name-only | sed -n -e 's/^"prettier@npm://' -e 's/"//p')" |
| 8 | + echo "[format] expected version is now ${EXERCISM_PRETTIER_VERSION:-}" |
| 9 | +fi |
| 10 | + |
| 11 | +if [ -z "${EXERCISM_PRETTIER_VERSION:-}" ]; then |
| 12 | + echo "Version could not be pulled using sed" >&2 |
| 13 | + echo "[format] pulling prettier version from yarn.lock using grep" |
| 14 | + EXERCISM_PRETTIER_VERSION="$(yarn info prettier --json --name-only | grep -Po '"prettier@npm:\K[^"]+')" |
| 15 | + echo "[format] expected version is now ${EXERCISM_PRETTIER_VERSION:-}" |
6 | 16 | fi
|
7 | 17 |
|
8 |
| -if [ -z "$EXERCISM_PRETTIER_VERSION" ]; then |
| 18 | +if [ -z "${EXERCISM_PRETTIER_VERSION:-}" ]; then |
| 19 | + echo "Version could not be pulled using grep or sed" >&2 |
| 20 | + echo "" |
9 | 21 | echo "---------------------------------------------------"
|
10 | 22 | echo "This script requires the EXERCISM_PRETTIER_VERSION variable to work."
|
11 | 23 | echo "Please see https://exercism.org/docs/building/markdown/style-guide for guidance."
|
12 | 24 | echo "---------------------------------------------------"
|
13 |
| - echo "This is what yarn list reports:" |
14 |
| - echo "$(yarn list prettier)" |
| 25 | + echo "$(yarn -v)" |
| 26 | + echo "" |
| 27 | + echo "This is what yarn why reports:" |
| 28 | + echo "$ yarn why prettier" |
| 29 | + echo "$(yarn why prettier)" |
| 30 | + echo "" |
| 31 | + echo "And yarn info reports the following:" |
| 32 | + echo "$ yarn info prettier --name-only" |
| 33 | + echo "$(yarn info prettier --name-only)" |
| 34 | + echo "" |
| 35 | + echo "This is the version that can be extracted using grep:" |
| 36 | + echo "$ yarn info prettier --json --name-only | grep -Po '"prettier@npm:\K[^"]+'" |
| 37 | + echo "└─ $(yarn info prettier --json --name-only | grep -Po '"prettier@npm:\K[^"]+')" |
15 | 38 | echo ""
|
16 |
| - echo "This is the version that can be extracted:" |
17 |
| - echo "$(yarn list --pattern prettier | grep -Po '.*\sprettier@\K.*')" |
| 39 | + echo "This is the version that can be extracted using sed:" |
| 40 | + echo "$ yarn info prettier --json --name-only | sed -n -e 's/^"prettier@npm://' -e 's/"//p'" |
| 41 | + echo "└─ $(yarn info prettier --json --name-only | sed -n -e 's/^"prettier@npm://' -e 's/"//p')" |
18 | 42 | echo ""
|
19 | 43 | echo "These files are found in the repo root:"
|
20 | 44 | echo "$(ls -p | grep -v /)"
|
21 | 45 | echo "---------------------------------------------------"
|
22 | 46 | exit 1
|
23 | 47 | else
|
24 |
| - echo "Running format with prettier@$EXERCISM_PRETTIER_VERSION" |
| 48 | + echo "[format] running with prettier@$EXERCISM_PRETTIER_VERSION" |
25 | 49 | fi
|
26 | 50 |
|
27 |
| -npx "prettier@$EXERCISM_PRETTIER_VERSION" --check "**/*.{js,jsx,ts,tsx,css,sass,scss,html,json,md,yml}" |
| 51 | +yarn dlx "prettier@$EXERCISM_PRETTIER_VERSION" --check "**/*.{js,jsx,ts,tsx,css,sass,scss,html,json,md,yml}" |
0 commit comments