Repository navigation
Expand file tree
/
Copy pathfmt.mk
More file actions
110 lines (93 loc) · 3.75 KB
/
Copy pathfmt.mk
File metadata and controls
110 lines (93 loc) · 3.75 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
# 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
# Centralized patterns - single source of truth
PRETTIER_PATTERNS := 'src/**/*.{ts,tsx,json}' 'src/node/workflowRuntime/*.js' 'scripts/lib/*.js' 'tests/**/*.ts' 'docs/**/*.mdx' 'package.json' 'tsconfig*.json' 'README.md'
# shfmt also walks node_modules trees (scripts/mintlify/node_modules holds Mintlify's own
# scripts), so the recipes format only the shell files it finds outside them.
SHELL_SCRIPTS = $$(shfmt -f scripts | grep -v '/node_modules/')
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)
NIX_FILES := flake.nix nix/package.nix
UV := $(shell command -v uv 2>/dev/null || (test -x $(HOME)/.local/bin/uv && echo $(HOME)/.local/bin/uv))
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 uv
.check-uv:
ifeq ($(UV),)
@echo "Error: uv not found. Install it: https://docs.astral.sh/uv/getting-started/installation/"
@exit 1
endif
# ruff comes from the ruff group in pyproject.toml, installed as uv.lock pins it.
fmt-python: .check-uv
@echo "Formatting Python files..."
@$(UV) run --locked --quiet --only-group ruff ruff format --quiet $(PYTHON_DIRS)
fmt-python-check: .check-uv
@echo "Checking Python formatting..."
@$(UV) run --locked --quiet --only-group ruff 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 files..."
@nix fmt -- $(NIX_FILES)
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 Nix formatting..."
@tmp_dir=$$(mktemp -d "$${TMPDIR:-/tmp}/fmt-nix-check.XXXXXX"); \
trap "rm -rf $$tmp_dir" EXIT; \
cp -r flake.nix flake.lock package.json bun.lock nix "$$tmp_dir/"; \
(cd "$$tmp_dir" && nix fmt -- $(NIX_FILES) >/dev/null 2>&1); \
for f in $(NIX_FILES); do \
if ! cmp -s "$$f" "$$tmp_dir/$$f"; then \
echo "$$f is not formatted correctly. Run 'make fmt-nix' to fix."; \
diff -u "$$f" "$$tmp_dir/$$f" || true; \
exit 1; \
fi; \
done
endif
fmt-sync-docs:
@bun scripts/gen_docs.ts
@bun scripts/gen_builtin_skills.ts --sync-xum-docs-skill
@bun scripts/gen_workflow_runtime_sources.ts
fmt-sync-docs-check:
@bun scripts/gen_docs.ts check
@bun scripts/gen_builtin_skills.ts check --sync-xum-docs-skill
@bun scripts/gen_workflow_runtime_sources.ts check