-
Notifications
You must be signed in to change notification settings - Fork 87
Expand file tree
/
Copy pathfmt.mk
More file actions
120 lines (101 loc) · 3.78 KB
/
fmt.mk
File metadata and controls
120 lines (101 loc) · 3.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# Formatting Rules
# ================
# This file contains all code formatting logic.
# Included by the main Makefile.
.PHONY: fmt fmt-check fmt-prettier fmt-prettier-check fmt-shell fmt-shell-check fmt-nix fmt-nix-check fmt-python fmt-python-check fmt-sync-docs fmt-sync-docs-check update-flake-hash flake-hash-check
# Centralized patterns - single source of truth
PRETTIER_PATTERNS := 'src/**/*.{ts,tsx,json}' 'mobile/**/*.{ts,tsx,json}' 'tests/**/*.ts' 'docs/**/*.mdx' 'package.json' 'tsconfig*.json' 'README.md'
SHELL_SCRIPTS := scripts
PYTHON_DIRS := benchmarks
# Always use bun x prettier for reproducibility (uses package.json version)
PRETTIER := bun x prettier
# Tool availability checks
SHFMT := $(shell command -v shfmt 2>/dev/null)
NIX := $(shell command -v nix 2>/dev/null)
UVX := $(shell command -v uvx 2>/dev/null || (test -x $(HOME)/.local/bin/uvx && echo $(HOME)/.local/bin/uvx))
fmt: fmt-prettier fmt-shell fmt-python fmt-nix fmt-sync-docs
@echo "==> All formatting complete!"
fmt-check: fmt-prettier-check fmt-shell-check fmt-python-check fmt-nix-check fmt-sync-docs-check
@echo "==> All formatting checks passed!"
fmt-prettier:
@echo "Formatting TypeScript/JSON/Markdown files..."
@$(PRETTIER) --cache --log-level error --write $(PRETTIER_PATTERNS)
fmt-prettier-check:
@echo "Checking TypeScript/JSON/Markdown formatting..."
@$(PRETTIER) --cache --log-level log --check $(PRETTIER_PATTERNS)
fmt-shell:
ifeq ($(SHFMT),)
@echo "Error: shfmt not found. Install with: brew install shfmt"
@exit 1
else
@echo "Formatting shell scripts..."
@shfmt -i 2 -ci -bn -w $(SHELL_SCRIPTS) >/dev/null
endif
fmt-shell-check:
ifeq ($(SHFMT),)
@echo "Error: shfmt not found. Install with: brew install shfmt"
@exit 1
else
@echo "Checking shell script formatting..."
@shfmt -i 2 -ci -bn -d $(SHELL_SCRIPTS)
endif
# Helper target to check for uvx
.check-uvx:
ifeq ($(UVX),)
@echo "Error: uvx not found. Install with: curl -LsSf https://astral.sh/uv/install.sh | sh"
@exit 1
endif
fmt-python: .check-uvx
@echo "Formatting Python files..."
@$(UVX) ruff format --quiet $(PYTHON_DIRS)
fmt-python-check: .check-uvx
@echo "Checking Python formatting..."
@$(UVX) ruff format --quiet --check $(PYTHON_DIRS)
fmt-nix:
ifeq ($(NIX),)
@echo "Nix not found; skipping Nix formatting"
else ifeq ($(wildcard flake.nix),)
@echo "flake.nix not found; skipping Nix formatting"
else
@echo "Formatting Nix flake..."
@nix fmt -- flake.nix
endif
fmt-nix-check:
ifeq ($(NIX),)
@echo "Nix not found; skipping Nix format check"
else ifeq ($(wildcard flake.nix),)
@echo "flake.nix not found; skipping Nix format check"
else
@echo "Checking flake.nix formatting..."
@tmp_dir=$$(mktemp -d "$${TMPDIR:-/tmp}/fmt-nix-check.XXXXXX"); \
trap "rm -rf $$tmp_dir" EXIT; \
cp flake.nix "$$tmp_dir/flake.nix"; \
(cd "$$tmp_dir" && nix fmt -- flake.nix >/dev/null 2>&1); \
if ! cmp -s flake.nix "$$tmp_dir/flake.nix"; then \
echo "flake.nix is not formatted correctly. Run 'make fmt-nix' to fix."; \
diff -u flake.nix "$$tmp_dir/flake.nix" || true; \
exit 1; \
fi
endif
update-flake-hash: ## Update flake.nix offlineCache outputHash from nix build output
ifeq ($(NIX),)
@echo "Nix not found; skipping flake hash update"
else ifeq ($(wildcard flake.nix),)
@echo "flake.nix not found; skipping flake hash update"
else
@./scripts/update_flake_hash.sh
endif
flake-hash-check: ## Verify flake.nix offlineCache outputHash is current
ifeq ($(NIX),)
@echo "Nix not found; skipping flake hash check"
else ifeq ($(wildcard flake.nix),)
@echo "flake.nix not found; skipping flake hash check"
else
@./scripts/update_flake_hash.sh --check
endif
fmt-sync-docs:
@bun scripts/gen_docs.ts
@bun scripts/gen_builtin_skills.ts --sync-mux-docs-skill
fmt-sync-docs-check:
@bun scripts/gen_docs.ts check
@bun scripts/gen_builtin_skills.ts check --sync-mux-docs-skill