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 " build-example-site: Builds hugo exampleSite."
45+ @echo " (Set BIOME_ARGS=write to enable --write, e.g. : make biome-all BIOME_ARGS=write)"
1546 @echo " <PRE-COMMIT>"
16- @echo " setup-pre-commit: Sets up pre-commit (assuming it is installed)"
47+ @echo " setup-pre-commit: Sets up pre-commit (assuming it is installed)"
1748 @echo " <PLAYWRIGHT TESTS>"
18- @echo " tests: Runs playwright against the new theme."
19- @echo " tests-update-screenshots: Runs playwright against the new theme."
49+ @echo " tests: Runs playwright against the new theme."
50+ @echo " tests-update-screenshots: Runs playwright against the new theme."
51+ @echo " <BIOME UTILITIES>"
52+ @echo " check-biome: Shows required vs local biome versions and the command that will run."
53+ @echo " install-help: Shows how to install Biome globally via brew or npm."
2054
21- .PHONY : biome-format biome-lint biome-all setup-pre-commit tests build-example-site
2255FLAG :=
2356ifeq ($(BIOME_ARGS ) , write)
24- FLAG := $(WRITE_FLAG)
57+ FLAG := $(WRITE_FLAG )
2558endif
2659
2760biome-format :
2861 $(BIOME_BASE_CMD ) format $(FLAG )
62+
2963biome-lint :
3064 $(BIOME_BASE_CMD ) lint $(FLAG )
65+
3166biome-all :
3267 $(BIOME_BASE_CMD ) check $(FLAG )
3368
3469setup-pre-commit :
35- @if ! command -v pre-commit & > /dev/null; then \
70+ @if ! command -v pre-commit > /dev/null 2>&1 ; then \
3671 echo " WARNING: 'pre-commit' is not installed. Please install it using: pip install pre-commit or brew install pre-commit" ; \
3772 else \
3873 echo " pre-commit is installed! Proceeding with hook installation." ; \
@@ -43,7 +78,38 @@ setup-pre-commit:
4378
4479build-example-site :
4580 cd exampleSite && hugo mod get && hugo build --gc -e production
81+
4682tests :
4783 cd tests && npx playwright test
84+
4885tests-update-screenshots :
4986 cd tests && npx playwright test --update-snapshots
87+
88+ check-biome :
89+ @echo " Required Biome version: $( BIOME_VERSION) "
90+ @echo " System Biome version: $( LOCAL_BIOME_VERSION) "
91+ @echo " Command that will run: $( BIOME_BASE_CMD) "
92+ @if ! command -v biome > /dev/null 2>&1 || [ " $( LOCAL_BIOME_VERSION) " != " $( BIOME_VERSION) " ]; then \
93+ echo " " ; \
94+ echo " ⚠️ Local biome version does not match required." ; \
95+ $(MAKE ) install-help; \
96+ fi
97+
98+ install-help :
99+ @echo " "
100+ @echo " 🛠️ Install options for biome v$( BIOME_VERSION) :"
101+ @echo " "
102+ @echo " 1) 🧪 Install manually via Homebrew (advanced):"
103+ @echo " # Find the correct commit SHA for biome $( BIOME_VERSION) here:"
104+ @echo " # https://github.com/Homebrew/homebrew-core/commits/master/Formula/biome.rb"
105+ @echo " curl -sSL https://raw.githubusercontent.com/Homebrew/homebrew-core/<COMMIT_SHA>/Formula/biome.rb -o biome.rb"
106+ @echo " brew install ./biome.rb"
107+ @echo " brew pin biome"
108+ @echo " "
109+ @echo " 2) 🚀 Install via npm (global):"
110+ @echo " npm install -g @biomejs/biome@$( BIOME_VERSION) "
111+ @echo " "
112+ @echo " 3) 🧰 Use temporarily via npx (auto fallback in Makefile):"
113+ @echo " npx -y @biomejs/biome@$( BIOME_VERSION) <command>"
114+ @echo " "
115+ @echo " Note: This Makefile will automatically fall back to npx if the right version is not found locally."
0 commit comments