1- BIOME_BASE_CMD :=
$(if $(shell which biome) ,biome,npx @biomejs/[email protected] ) 1+ # Read the Biome version from biome.json "$schema"
2+ # Uses BSD/GNU compatible sed with -E for extended regex.
3+ BIOME_VERSION := $(shell sed -nE 's/.* schemas\/([0-9]+\.[0-9]+\.[0-9]+) \/schema\.json.*/\1/p' biome.json)
4+
5+ # Detect local biome and its version (if any)
6+ HAVE_BIOME := $(shell command -v biome >/dev/null 2>&1 && echo yes || echo no)
7+ LOCAL_BIOME_VERSION := $(shell biome --version 2>/dev/null | sed -E 's/[^0-9]* ([0-9]+\.[0-9]+\.[0-9]+) .*/\1/')
8+
9+ # Choose which command to run. Prefer local only if versions match.
10+ ifeq ($(strip $(BIOME_VERSION ) ) ,)
11+ $(warning Could not determine Biome version from biome.json; defaulting to npx @biomejs/biome)
12+ BIOME_BASE_CMD := npx -y @biomejs/biome
13+ else
14+ ifeq ($(HAVE_BIOME),yes)
15+ ifeq ($(LOCAL_BIOME_VERSION),$(BIOME_VERSION))
16+ BIOME_BASE_CMD := biome
17+ else
18+ $(warning Found biome $(LOCAL_BIOME_VERSION) on PATH, but required $(BIOME_VERSION). Falling back to npx.)
19+ BIOME_BASE_CMD := npx -y @biomejs/biome@$(BIOME_VERSION )
20+ endif
21+ else
22+ BIOME_BASE_CMD := npx -y @biomejs/biome@$(BIOME_VERSION )
23+ endif
24+ endif
25+
26+ # Optional: allow forcing use of local biome anyway (not recommended)
27+ # Usage: make ... FORCE_LOCAL_BIOME=1
28+ ifeq ($(FORCE_LOCAL_BIOME ) ,1)
29+ BIOME_BASE_CMD := biome
30+ endif
31+
232WRITE_FLAG := --write
333
4- .PHONY : list help
5- list help ::
6- $(info Available Make targets:)
34+ .PHONY : list help biome-format biome-lint biome-all setup-pre-commit tests build-example-site check-biome install-help tests-update-screenshots
35+
36+ list help :
37+ @echo " Available Make targets:"
738 @echo " <COMMON>"
8- @echo " list | help: Print these available make targets"
39+ @echo " list | help: Print these available make targets"
940 @echo " <LINTING AND FORMATTING>"
10- @echo " biome-format: Runs the biome formatter."
11- @echo " biome-lint: Runs the biome linter."
12- @echo " biome-all: Runs both the lint and formatting commands."
13- @echo " build-example-site: Builds hugo exampleSite."
14- @echo " (Set BIOME_ARGS to add additional arguments to biome command (ex: make biome-all BIOME_ARGS=write))"
41+ @echo " biome-format: Runs the biome formatter."
42+ @echo " biome-lint: Runs the biome linter."
43+ @echo " biome-all: Runs both the lint and formatting commands."
44+ @echo " (Set BIOME_ARGS=write to enable --write, e.g.: make biome-all BIOME_ARGS=write)"
45+ @echo " <BUILD>"
46+ @echo " build-example-site: Builds hugo exampleSite."
1547 @echo " <PRE-COMMIT>"
16- @echo " setup-pre-commit: Sets up pre-commit (assuming it is installed)"
48+ @echo " setup-pre-commit: Sets up pre-commit (assuming it is installed)"
1749 @echo " <PLAYWRIGHT TESTS>"
18- @echo " tests: Runs playwright against the new theme."
19- @echo " tests-update-screenshots: Runs playwright against the new theme."
50+ @echo " tests: Runs playwright against the new theme."
51+ @echo " tests-update-screenshots: Runs playwright against the new theme and generates screenshots."
52+ @echo " <BIOME UTILITIES>"
53+ @echo " check-biome: Shows required vs local biome versions and the command that will run."
54+ @echo " install-help: Shows how to install Biome globally via brew or npm."
2055
21- .PHONY : biome-format biome-lint biome-all setup-pre-commit tests build-example-site
2256FLAG :=
2357ifeq ($(BIOME_ARGS ) , write)
24- FLAG := $(WRITE_FLAG)
58+ FLAG := $(WRITE_FLAG )
2559endif
2660
2761biome-format :
2862 $(BIOME_BASE_CMD ) format $(FLAG )
63+
2964biome-lint :
3065 $(BIOME_BASE_CMD ) lint $(FLAG )
66+
3167biome-all :
3268 $(BIOME_BASE_CMD ) check $(FLAG )
3369
3470setup-pre-commit :
35- @if ! command -v pre-commit & > /dev/null; then \
71+ @if ! command -v pre-commit > /dev/null 2>&1 ; then \
3672 echo " WARNING: 'pre-commit' is not installed. Please install it using: pip install pre-commit or brew install pre-commit" ; \
3773 else \
3874 echo " pre-commit is installed! Proceeding with hook installation." ; \
@@ -43,7 +79,38 @@ setup-pre-commit:
4379
4480build-example-site :
4581 cd exampleSite && hugo mod get && hugo build --gc -e production
82+
4683tests :
4784 cd tests && npx playwright test
85+
4886tests-update-screenshots :
4987 cd tests && npx playwright test --update-snapshots
88+
89+ check-biome :
90+ @echo " Required Biome version: $( BIOME_VERSION) "
91+ @echo " System Biome version: $( LOCAL_BIOME_VERSION) "
92+ @echo " Command that will run: $( BIOME_BASE_CMD) "
93+ @if ! command -v biome > /dev/null 2>&1 || [ " $( LOCAL_BIOME_VERSION) " != " $( BIOME_VERSION) " ]; then \
94+ echo " " ; \
95+ echo " ⚠️ Local biome version does not match required." ; \
96+ $(MAKE ) install-help; \
97+ fi
98+
99+ install-help :
100+ @echo " "
101+ @echo " 🛠️ Install options for biome v$( BIOME_VERSION) :"
102+ @echo " "
103+ @echo " 1) 🧪 Install manually via Homebrew (advanced):"
104+ @echo " # Find the correct commit SHA for biome $( BIOME_VERSION) here:"
105+ @echo " # https://github.com/Homebrew/homebrew-core/commits/master/Formula/biome.rb"
106+ @echo " curl -sSL https://raw.githubusercontent.com/Homebrew/homebrew-core/<COMMIT_SHA>/Formula/biome.rb -o biome.rb"
107+ @echo " brew install ./biome.rb"
108+ @echo " brew pin biome"
109+ @echo " "
110+ @echo " 2) 🚀 Install via npm (global):"
111+ @echo " npm install -g @biomejs/biome@$( BIOME_VERSION) "
112+ @echo " "
113+ @echo " 3) 🧰 Use temporarily via npx (auto fallback in Makefile):"
114+ @echo " npx -y @biomejs/biome@$( BIOME_VERSION) <command>"
115+ @echo " "
116+ @echo " Note: This Makefile will automatically fall back to npx if the right version is not found locally."
0 commit comments