|
| 1 | +.SUFFIXES: |
| 2 | + |
| 3 | +all: |
| 4 | + |
| 5 | +# runs all the test files. |
| 6 | +test: |
| 7 | + nvim --version | head -n 1 && echo '' |
| 8 | + nvim --headless --noplugin -u ./scripts/minimal_init.lua \ |
| 9 | + -c "lua require('mini.test').setup()" \ |
| 10 | + -c "lua MiniTest.run({ execute = { reporter = MiniTest.gen_reporter.stdout({ group_depth = 1 }) } })" |
| 11 | + |
| 12 | +# installs `mini.nvim`, used for both the tests and documentation. |
| 13 | +deps: |
| 14 | + @mkdir -p deps |
| 15 | + git clone --depth 1 https://github.com/echasnovski/mini.nvim deps/mini.nvim |
| 16 | + |
| 17 | +# installs deps before running tests, useful for the CI. |
| 18 | +test-ci: deps test |
| 19 | + |
| 20 | +# generates the documentation. |
| 21 | +documentation: |
| 22 | + nvim --headless --noplugin -u ./scripts/minimal_init.lua -c "luafile ./scripts/docgen.lua" -c "qa!" |
| 23 | + |
| 24 | +# installs deps before running the documentation generation, useful for the CI. |
| 25 | +documentation-ci: deps documentation |
| 26 | + |
| 27 | +# performs a lint check and fixes issues if possible, following the config in `stylua.toml`. |
| 28 | +lint: |
| 29 | + stylua . |
| 30 | + |
| 31 | +# installs the repo pre-commit hook that runs `make precommit` before every commit. |
| 32 | +precommit-install: |
| 33 | + @mkdir -p .git/hooks |
| 34 | + @printf '#!/usr/bin/env bash\nmake precommit\n' > .git/hooks/pre-commit |
| 35 | + @chmod +x .git/hooks/pre-commit |
| 36 | + @echo "pre-commit hook installed at .git/hooks/pre-commit" |
| 37 | + |
| 38 | +# runs the pre-commit checks: lints all Lua files (auto-fixing anything that |
| 39 | +# isn't formatted), regenerates docs, and re-stages any files that changed. |
| 40 | +precommit: |
| 41 | + @set -eu; \ |
| 42 | + if command -v stylua >/dev/null 2>&1; then \ |
| 43 | + stylua .; \ |
| 44 | + reformatted=$$(git diff --name-only -- '*.lua'); \ |
| 45 | + if [ -n "$$reformatted" ]; then \ |
| 46 | + echo "precommit: re-staging stylua-formatted files:"; \ |
| 47 | + echo "$$reformatted" | sed 's/^/ /'; \ |
| 48 | + git add $$reformatted; \ |
| 49 | + fi; \ |
| 50 | + stylua --check .; \ |
| 51 | + else \ |
| 52 | + echo "precommit: stylua not installed; skipping lint" >&2; \ |
| 53 | + fi; \ |
| 54 | + $(MAKE) documentation; \ |
| 55 | + git add doc |
| 56 | + |
| 57 | +clean: |
| 58 | + rm -rf deps |
0 commit comments