-
Notifications
You must be signed in to change notification settings - Fork 15
/
gendossier.sh
executable file
·166 lines (139 loc) · 3.89 KB
/
gendossier.sh
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#!/bin/bash
#
# Generates various resources for Dossier.
set -e
readonly ROOT="$(cd $(dirname $0) && pwd)"
readonly RESOURCES="${ROOT}/src/java/com/github/jsdossier/resources"
readonly GOOGLE_JAVA_FORMAT="${ROOT}/third_party/java/google_java_format/google-java-format-1.3-all-deps.jar"
readonly BAZEL="$(which bazelisk)"
usage() {
cat <<EOF
usage $0 [...options]
Generate various resources for Dossier. If no options are specified,
builds a new release (-r).
OPTIONS:
-h Print this help message and exit
-d Refresh the project's readme documentation
-f Format all java code
-b Format all Bazel/Starlark code
-j Run the Closure Compiler on dossier.js
-l Run lessc on dossier.less
-r Build a release
-s Build sample documentation for dossier.js
-t Run all tests
EOF
}
run_jsc() {
"${BAZEL}" build //src/js:all
}
run_lessc() {
if type -P lessc >/dev/null; then
lessc --clean-css="--s0 --advanced" --autoprefix="last 2 versions, edge > 12" \
src/css/dossier.less \
$RESOURCES/dossier.css
else
echo >&2 "[ERROR] lessc not found: install node from https://nodejs.org, then run:"
echo >&2 " $ npm install -g less less-plugin-clean-css less-plugin-autoprefix"
exit 2
fi
}
run_tests() {
"${BAZEL}" test //test/...
}
build_release() {
"${BAZEL}" clean && \
"${BAZEL}" test //test/... && \
"${BAZEL}" build :release && \
echo "Release built: bazel-genfiles/js-dossier.tar.gz"
}
build_sample() {
"${BAZEL}" build //src/java/com/github/jsdossier:dossier_deploy.jar
java -agentlib:jdwp=transport=dt_socket,server=y,suspend="${DEBUG:-n}",address=5005 \
-jar bazel-bin/src/java/com/github/jsdossier/dossier_deploy.jar \
--config sample_config.json
}
update_readme() {
"${BAZEL}" build :readme && cp bazel-genfiles/README.md README.md
}
format_java() {
cd "${ROOT}"
java -jar "${GOOGLE_JAVA_FORMAT}" -i $(find src test -name *.java)
}
buildifier() {
# Note, this relies on buildifier being installed in the $PATH
find . -type f \( -name \"*.bzl\" -or -name WORKSPACE -or -name BUILD -or -name BUILD.bazel \) ! -path \"./third_party/*\" | xargs buildifier -v --warnings=attr-cfg,attr-license,attr-non-empty,attr-output-default,attr-single-file,confusing-name,constant-glob,ctx-actions,ctx-args,depset-iteration,depset-union,dict-concatenation,duplicated-name,filetype,function-docstring,git-repository,http-archive,integer-division,load,load-on-top,module-docstring,name-conventions,native-build,native-package,out-of-order-load,output-group,package-name,package-on-top,positional-args,redefined-variable,repository-name,return-value,same-origin-load,string-iteration,unreachable,unsorted-dict-items,unused-variable
}
main() {
if [[ -z "${BAZEL}" ]]; then
echo "bazelisk not installed: https://github.com/bazelbuild/bazelisk"
exit 1
fi
local no_options=1
local js=0
local less=0
local readme=0
local release=0
local sample=0
local test=0
while getopts "bdfhjlprst" option
do
case $option in
h)
usage
exit 0
;;
d)
no_options=0; readme=1
;;
f)
no_options=0; format=1
;;
b)
no_options=0; buildifier=1
;;
j)
no_options=0; js=1
;;
l)
no_options=0; less=1
;;
r)
no_options=0; release=1
;;
s)
no_options=0; sample=1
;;
t)
no_options=0; test=1
;;
esac
done
if (( $no_options )); then
release=1
fi
if (( $format )); then
format_java
fi
if (( $readme )); then
update_readme
fi
if (( $js )); then
run_jsc
fi
if (( $less )); then
run_lessc
fi
if (( $test )); then
run_tests
fi
if (( $release )); then
build_release
fi
if (( $sample )); then
build_sample
fi
if (( $buildifier )); then
buildifier
fi
}
main $@