forked from haacked/ai-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfmt
executable file
·82 lines (71 loc) · 1.94 KB
/
fmt
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
#!/usr/bin/env bash
#/ Usage: script/fmt [-c|--check]
#/ Description: Runs all formatters on the codebase.
#/ Options:
#/ -c, --check - Run in check mode. Will return a non-zero exit code if anything needs reformatting.
{ set +x; } 2>/dev/null
source_dir="$( cd -P "$( dirname "$0" )" >/dev/null 2>&1 && pwd )"
root_dir=$(cd $source_dir && cd ../ && pwd)
cd $root_dir
source script/helpers/_utils.sh
SOLUTION_FILE="AIDemo.sln"
PROJECT_DIR="./src/AIDemo.Web"
check=false
while (( "$#" )); do
key="$1"
shift
case "$key" in
-c|--check)
check=true
;;
-\?|-h|--help)
grep '^#/' <"$0" | cut -c4-
exit
;;
esac
done
if $check; then
echo "Running in check mode: Will return a non-zero exit code if anything needs reformatting."
else
echo "Running in reformat mode: Will automatically reformat files if they need reformatting."
fi
success=true
if type dotnet >/dev/null 2>&1; then
dotnet_args=("--exclude=$PROJECT_DIR/Migrations")
if $check; then
dotnet_args+=("--verify-no-changes")
fi
echo "Running .NET Formatters..."
# Run just 'whitespace' and 'style' formatters, not 'analyzer' formatters!
if ! dotnet format whitespace "$SOLUTION_FILE" "${dotnet_args[@]}"; then
success=false
fi
if ! dotnet format style "$SOLUTION_FILE" "${dotnet_args[@]}"; then
success=false
fi
elif $check; then
echo ".NET CLI is not installed!" 1>&2
exit 1
fi
if type npm >/dev/null 2>&1; then
if $check; then
npm_command="lint"
else
npm_command="lint:fix"
fi
echo "Running ECMAScript/TypeScript Formatters..."
cd "$PROJECT_DIR"
npm ci
if ! npm run "$npm_command"; then
success=false
fi
elif $check; then
echo "NPM is not installed!" 1>&2
exit 1
fi
if $success; then
echo "You're all good!"
else
echo "Formatting is no good! Run 'script/fmt' to fix" 1>&2
exit 1
fi