mirror of
https://github.com/chenasraf/pantry-flutter.git
synced 2026-05-17 17:28:03 +00:00
build: use lefthook for hooks
This commit is contained in:
69
Makefile
69
Makefile
@@ -1,9 +1,6 @@
|
|||||||
# Version from pubspec.yaml (without build number)
|
# Version from pubspec.yaml (without build number)
|
||||||
VERSION := $(shell grep '^version:' pubspec.yaml | sed 's/version: *//;s/+.*//')
|
VERSION := $(shell grep '^version:' pubspec.yaml | sed 's/version: *//;s/+.*//')
|
||||||
|
|
||||||
# Get staged Dart files
|
|
||||||
STAGED_DART_FILES := $(shell git diff --cached --name-only --diff-filter=ACM | grep '\.dart$$' 2>/dev/null)
|
|
||||||
|
|
||||||
# Default target
|
# Default target
|
||||||
.PHONY: help
|
.PHONY: help
|
||||||
help:
|
help:
|
||||||
@@ -12,7 +9,7 @@ help:
|
|||||||
@echo " Setup:"
|
@echo " Setup:"
|
||||||
@echo " get Install dependencies"
|
@echo " get Install dependencies"
|
||||||
@echo " clean Clean build artifacts"
|
@echo " clean Clean build artifacts"
|
||||||
@echo " install-precommit Install git pre-commit hook"
|
@echo " install-hooks Install git hooks via lefthook"
|
||||||
@echo " pods Update CocoaPods repo and install pods"
|
@echo " pods Update CocoaPods repo and install pods"
|
||||||
@echo ""
|
@echo ""
|
||||||
@echo " i18n:"
|
@echo " i18n:"
|
||||||
@@ -22,13 +19,9 @@ help:
|
|||||||
@echo " Development:"
|
@echo " Development:"
|
||||||
@echo " run Run the app in debug mode"
|
@echo " run Run the app in debug mode"
|
||||||
@echo " webapp-run Run the web app in default browser"
|
@echo " webapp-run Run the web app in default browser"
|
||||||
@echo " format Format staged Dart files"
|
@echo " format Format all Dart files"
|
||||||
@echo " analyze Analyze staged Dart files"
|
@echo " analyze Analyze all Dart files"
|
||||||
@echo " check Check staged files (format + analyze, no changes)"
|
@echo " check Check all files (format + analyze, no changes)"
|
||||||
@echo " precommit Run pre-commit checks on staged files"
|
|
||||||
@echo " format-all Format all Dart files"
|
|
||||||
@echo " analyze-all Analyze all Dart files"
|
|
||||||
@echo " check-all Check all files (format + analyze, no changes)"
|
|
||||||
@echo ""
|
@echo ""
|
||||||
@echo " Testing:"
|
@echo " Testing:"
|
||||||
@echo " test Run all tests"
|
@echo " test Run all tests"
|
||||||
@@ -96,50 +89,14 @@ webapp-run:
|
|||||||
|
|
||||||
.PHONY: format
|
.PHONY: format
|
||||||
format:
|
format:
|
||||||
@if [ -n "$(STAGED_DART_FILES)" ]; then \
|
dart format .
|
||||||
echo "Formatting staged files..."; \
|
|
||||||
dart format $(STAGED_DART_FILES); \
|
|
||||||
else \
|
|
||||||
echo "No staged Dart files to format."; \
|
|
||||||
fi
|
|
||||||
|
|
||||||
.PHONY: analyze
|
.PHONY: analyze
|
||||||
analyze:
|
analyze:
|
||||||
@if [ -n "$(STAGED_DART_FILES)" ]; then \
|
flutter analyze --no-fatal-infos
|
||||||
echo "Analyzing staged files..."; \
|
|
||||||
dart analyze $(STAGED_DART_FILES); \
|
|
||||||
else \
|
|
||||||
echo "No staged Dart files to analyze."; \
|
|
||||||
fi
|
|
||||||
|
|
||||||
.PHONY: check
|
.PHONY: check
|
||||||
check:
|
check:
|
||||||
@if [ -n "$(STAGED_DART_FILES)" ]; then \
|
|
||||||
echo "Checking staged files..."; \
|
|
||||||
dart format --output=none --set-exit-if-changed $(STAGED_DART_FILES); \
|
|
||||||
dart analyze $(STAGED_DART_FILES); \
|
|
||||||
else \
|
|
||||||
echo "No staged Dart files to check."; \
|
|
||||||
fi
|
|
||||||
|
|
||||||
.PHONY: precommit
|
|
||||||
precommit: format analyze
|
|
||||||
@if [ -n "$(STAGED_DART_FILES)" ]; then \
|
|
||||||
echo "Re-staging formatted files..."; \
|
|
||||||
git add $(STAGED_DART_FILES); \
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Full project commands
|
|
||||||
.PHONY: format-all
|
|
||||||
format-all:
|
|
||||||
dart format .
|
|
||||||
|
|
||||||
.PHONY: analyze-all
|
|
||||||
analyze-all:
|
|
||||||
flutter analyze --no-fatal-infos
|
|
||||||
|
|
||||||
.PHONY: check-all
|
|
||||||
check-all:
|
|
||||||
dart format --output=none --set-exit-if-changed .
|
dart format --output=none --set-exit-if-changed .
|
||||||
flutter analyze --no-fatal-infos
|
flutter analyze --no-fatal-infos
|
||||||
|
|
||||||
@@ -252,17 +209,9 @@ pods:
|
|||||||
cd macos && pod install --repo-update
|
cd macos && pod install --repo-update
|
||||||
|
|
||||||
# Git hooks
|
# Git hooks
|
||||||
.PHONY: install-precommit
|
.PHONY: install-hooks
|
||||||
install-precommit:
|
install-hooks:
|
||||||
@if [ ! -f .git/hooks/pre-commit ]; then \
|
lefthook install
|
||||||
echo "Installing pre-commit hook..."; \
|
|
||||||
echo '#!/bin/sh' > .git/hooks/pre-commit; \
|
|
||||||
echo 'make precommit' >> .git/hooks/pre-commit; \
|
|
||||||
chmod +x .git/hooks/pre-commit; \
|
|
||||||
echo "Pre-commit hook installed."; \
|
|
||||||
else \
|
|
||||||
echo "Pre-commit hook already exists, skipping."; \
|
|
||||||
fi
|
|
||||||
|
|
||||||
# API
|
# API
|
||||||
.PHONY: fetch-openapi
|
.PHONY: fetch-openapi
|
||||||
|
|||||||
9
lefthook.yml
Normal file
9
lefthook.yml
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
pre-commit:
|
||||||
|
commands:
|
||||||
|
format:
|
||||||
|
glob: "*.dart"
|
||||||
|
run: dart format {staged_files}
|
||||||
|
stage_fixed: true
|
||||||
|
analyze:
|
||||||
|
glob: "*.dart"
|
||||||
|
run: dart analyze {staged_files}
|
||||||
Reference in New Issue
Block a user