-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmake.zsh
executable file
·84 lines (68 loc) · 1.6 KB
/
make.zsh
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
#!/bin/zsh
BIN_NAME="szmaterlok"
BIN_PATH="./cmd"
WATCH_SLEEP=3
function go:watch { # watch for changes and rebuild go binaries
go:build
./$BIN_NAME &
binpid=$!
max=0
while true; do
# find files newer than built binary
files=( $(find . -newer $BIN_NAME -and \( \
-name '*.go' \
-or -name '*.mod' \
-or -name '*.sum' \
-or -name '*.json' \
-or -name '*.js' \
-or -name '*.html' \
-or -name '*.css' \)) )
# if there are any files newer than built binary
# rebuild and run szmaterlok executable again
if (( ${#files[@]} > 0 )); then
kill -INT $binpid
go:build
./$BIN_NAME &
binpid=$!
fi
# wait for next iteration
sleep $WATCH_SLEEP
done
}
function go:build { # build go binaries
go build -o $BIN_NAME $BIN_PATH
}
function go:run { # run go backend server
go:build
./$BIN_NAME
}
function go:test { # run go unit tests
go test -v ./...
}
function go:clean { # remove go built binaries
rm -rf $BIN_NAME
}
function go:lint { # lint go files in repository
go build ./...
go vet ./...
}
function go:fmt { # format all go files in repository
go fmt ./...
}
function fmt { # format all files in repository
go:fmt
deno fmt
}
function clean { # remove all build artifacts
go:clean
}
function default {
go:build
}
function help {
echo "$0 <task> <args>"
echo "Tasks:"
print -l ${(ok)functions} | cat -n
}
TIMEFORMAT="Task completed in %3lR"
time ${@:-default}