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
+
2
32
WRITE_FLAG := --write
3
33
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:"
7
38
@echo " <COMMON>"
8
- @echo " list | help: Print these available make targets"
39
+ @echo " list | help: Print these available make targets"
9
40
@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)"
15
46
@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)"
17
48
@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."
20
54
21
- .PHONY : biome-format biome-lint biome-all setup-pre-commit tests build-example-site
22
55
FLAG :=
23
56
ifeq ($(BIOME_ARGS ) , write)
24
- FLAG := $(WRITE_FLAG)
57
+ FLAG := $(WRITE_FLAG )
25
58
endif
26
59
27
60
biome-format :
28
61
$(BIOME_BASE_CMD ) format $(FLAG )
62
+
29
63
biome-lint :
30
64
$(BIOME_BASE_CMD ) lint $(FLAG )
65
+
31
66
biome-all :
32
67
$(BIOME_BASE_CMD ) check $(FLAG )
33
68
34
69
setup-pre-commit :
35
- @if ! command -v pre-commit & > /dev/null; then \
70
+ @if ! command -v pre-commit > /dev/null 2>&1 ; then \
36
71
echo " WARNING: 'pre-commit' is not installed. Please install it using: pip install pre-commit or brew install pre-commit" ; \
37
72
else \
38
73
echo " pre-commit is installed! Proceeding with hook installation." ; \
@@ -43,7 +78,38 @@ setup-pre-commit:
43
78
44
79
build-example-site :
45
80
cd exampleSite && hugo mod get && hugo build --gc -e production
81
+
46
82
tests :
47
83
cd tests && npx playwright test
84
+
48
85
tests-update-screenshots :
49
86
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