Skip to content

Commit

Permalink
convert check-yarn to bash and move to repo root
Browse files Browse the repository at this point in the history
  • Loading branch information
sndrs committed Nov 7, 2023
1 parent f865157 commit 2af6b0e
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 71 deletions.
4 changes: 2 additions & 2 deletions dotcom-rendering/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ validate-build: # private

check-env: # private
$(call log, "checking environment")
@ cd .. && scripts/env/check-node
@node scripts/env/check-yarn.js
@cd .. && scripts/env/check-node
@cd .. && scripts/env/check-yarn

clear: # private
@clear
Expand Down
32 changes: 0 additions & 32 deletions dotcom-rendering/scripts/env/check-yarn.js

This file was deleted.

37 changes: 0 additions & 37 deletions dotcom-rendering/scripts/env/ensure.js

This file was deleted.

38 changes: 38 additions & 0 deletions scripts/env/check-yarn
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env bash

# Check that yarn is available. If not, ask the user to run `corepack enable`
# which will provide it. Note that any yarn@>1 will do, since it will defer to
# the copy in that lives in .yarn/releases (which is the version we want to
# use).

in_terminal() { test -t 1; }

strip_colors() {
local text="$1"
printf "$text" | sed -e $'s/\x1b\[[0-9;]*m//g'
}

log_with_color() {
local text="$1"

# Check if output is a terminal and supports color
if in_terminal && [[ $(tput colors) -ge 8 ]]; then
# Terminal supports color, print the text as it is
echo -e "$text"
else
# Terminal does not support color, strip color codes and print
echo "$(strip_colors "$text")"
fi
}

blue='\033[0;34m'
red='\033[0;31m'
dim='\033[2m'
reset='\033[0m'

if ! command -v yarn &> /dev/null; then
log_with_color "${red}Could not find yarn. Please run 'corepack enable'.${reset}"
exit 1
fi

log_with_color "${dim}Using yarn ${blue}$(yarn -v)${reset}"

0 comments on commit 2af6b0e

Please sign in to comment.