-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-workflow.zsh
executable file
·128 lines (101 loc) · 2.09 KB
/
build-workflow.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/usr/bin/env zsh
# programs & scripts
wffiles=(transmit OpenFavourite.js)
# icons
wffiles+=(icon.png update.png)
# data files
wffiles+=(info.plist README.md LICENCE.txt)
here="$( cd "$( dirname "$0" )"; pwd )"
log() {
echo "$@" > /dev/stderr
}
do_dist=0
do_clean=0
usage() {
cat <<EOS
build-workflow.zsh [options]
Usage:
build-workflow.zsh [-d] [-c]
build-workflow.zsh -h
Options:
-d Build .alfredworkflow file
-c Remove build directory
-h Show this help message and exit
EOS
}
while getopts ":cdh" opt; do
case $opt in
c)
do_clean=1
;;
d)
do_dist=1
;;
h)
usage
exit 0
;;
\?)
log "Invalid option: -$OPTARG"
exit 1
;;
esac
done
shift $((OPTIND-1))
cleanup() {
local p="${here}/build"
log "Cleaning up ..."
test -d "$p" && rm -rf ./build/
}
pushd "$here" &> /dev/null
log "Building executable(s) ..."
go build -v -o ./transmit ./cmd/
ST_BUILD=$?
if [ "$ST_BUILD" != 0 ]; then
log "Error building executable."
cleanup
popd &> /dev/null
exit $ST_BUILD
fi
chmod 755 ./transmit
log
log "Cleaning ./build ..."
rm -rvf ./build
log
log "Copying assets to ./build ..."
mkdir -vp ./build
for n in $wffiles; do
cp -v "$n" ./build/
done
log
if [[ $do_dist -eq 1 ]]; then
# Get the dist filename from the executable
zipfile="$(./transmit --distname 2> /dev/null)"
if [ "$?" -ne 0 ]; then
log "Error getting distname from transmit."
cleanup
exit 1
fi
log
if test -e "$zipfile"; then
log "Removing existing .alfredworkflow file ..."
rm -rvf "$zipfile"
log
fi
pushd ./build/ &> /dev/null
log "Building .alfredworkflow file ..."
zip -r8n .png "../${zipfile}" ./*
ST_ZIP=$?
if [ "$ST_ZIP" != 0 ]; then
log "Error creating .alfredworkflow file."
popd &> /dev/null
cleanup
popd &> /dev/null
exit $ST_ZIP
fi
popd &> /dev/null
log
log "Wrote '${zipfile}' in '$( pwd )'"
fi
[[ $do_clean -eq 1 ]] && { cleanup }
popd &> /dev/null