-
Notifications
You must be signed in to change notification settings - Fork 109
/
Copy path_build_plantuml.sh
executable file
·72 lines (56 loc) · 1.63 KB
/
_build_plantuml.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
#!/usr/bin/env bash
##
# _build_plantuml.sh
#
# searches through repo for plantuml sources matching $PUML_MATCH
# and exports them using `node-plantuml`.
#
# In order to build deterministic .svgs, we use a puml docker image that is
# pegged to a specific version
##
set -eu
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
PUML_PORT=9999
export PUML_BASE_URL=http://localhost:${PUML_PORT}
# Match filenames ending with .puml or .plantuml by default
PUML_MATCH=${PUML_MATCH:=*.p*uml}
# if MODE=STAGED_GIT, then search staged git files
# if MODE=ALL, then search the whole repo
MODE=${MODE:=ALL}
trap ctrl_c INT
function ctrl_c() {
echo "exit early - stopping docker"
docker stop puml-local
exit 1
}
# run the docker puml server
docker run -d --rm \
--name puml-local \
-p ${PUML_PORT}:8080 \
plantuml/plantuml-server:jetty-v1.2024.7
# Wait for docker to be up
sleep 2
echo "Searching for ${MODE} files matching pattern: ${PUML_MATCH}"
case ${MODE} in
# search only for the staged files - much faster to run as a git hook
STAGED_GIT)
for i in $(git diff --staged --name-only `find ${DIR}/../docs -name ${PUML_MATCH}`); do
echo "rendering .puml -> .svg for diagram diagram: $i"
# add the .svg file alongside the original
${DIR}/_render_svg.mjs $i
done
;;
# search all files
ALL)
for i in $(find ${DIR}/../docs -name ${PUML_MATCH}); do
echo "rendering .puml -> .svg for diagram diagram: $i"
# add the .svg file alongside the original
${DIR}/_render_svg.mjs $i
done
;;
*)
echo "unsupported search MODE:${MODE}"
exit 1
;;
esac
docker stop puml-local