forked from EPNW/opus_flutter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathformat.sh
More file actions
executable file
·85 lines (71 loc) · 2.45 KB
/
format.sh
File metadata and controls
executable file
·85 lines (71 loc) · 2.45 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
#!/usr/bin/env bash
#
# format.sh
#
# Checks that all Dart code in the monorepo is formatted correctly.
# Exits with a non-zero code if any file needs formatting.
#
# Usage:
# ./scripts/format.sh
#
# Requirements:
# - dart (bundled with flutter)
set -uo pipefail
# shellcheck source=scripts/common.sh
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/common.sh"
# ---------------------------------------------------------------------------
# Tracking
# ---------------------------------------------------------------------------
failed_packages=()
passed_packages=()
# ---------------------------------------------------------------------------
# Main
# ---------------------------------------------------------------------------
echo -e "${BOLD}Format check — $(date '+%Y-%m-%d %H:%M')${NC}"
echo "Root: $ROOT_DIR"
log_header "━━━ Checking formatting ━━━"
for package in "$DART_PACKAGE" "${FLUTTER_PACKAGES[@]}"; do
local_dir="$ROOT_DIR/$package"
if [ ! -d "$local_dir" ]; then
log_warning "Directory not found, skipping: $local_dir"
continue
fi
log_header "▸ $package"
# Resolve packages so the formatter can read analysis_options.yaml.
if [ "$package" = "$DART_PACKAGE" ]; then
(cd "$local_dir" && dart pub get) || true
else
(cd "$local_dir" && flutter pub get) || true
fi
if dart format --set-exit-if-changed "$local_dir/"; then
log_success "$package"
passed_packages+=("$package")
else
log_error "$package"
failed_packages+=("$package")
fi
done
# ---------------------------------------------------------------------------
# Summary
# ---------------------------------------------------------------------------
echo ""
echo -e "${BOLD}════════════════════════════════════════${NC}"
echo -e "${BOLD}Results${NC}"
echo -e "${BOLD}════════════════════════════════════════${NC}"
if [ ${#passed_packages[@]} -gt 0 ]; then
echo -e "${GREEN}Passed (${#passed_packages[@]}):${NC}"
for pkg in "${passed_packages[@]}"; do
echo -e " ${GREEN}✓${NC} $pkg"
done
fi
if [ ${#failed_packages[@]} -gt 0 ]; then
echo ""
echo -e "${RED}Failed (${#failed_packages[@]}):${NC}"
for pkg in "${failed_packages[@]}"; do
echo -e " ${RED}✗${NC} $pkg"
done
echo ""
exit 1
fi
echo ""
echo -e "${GREEN}${BOLD}All packages are properly formatted!${NC}"