-
Notifications
You must be signed in to change notification settings - Fork 0
/
jsdoc.sh
executable file
·56 lines (50 loc) · 1.5 KB
/
jsdoc.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
#!/usr/bin/env bash
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
#
# jsdoc wrapper used by the "jsdoc" package.json script
#
# Removes the existing destination directory if it exists, runs JSDoc, and emits
# the relative path to the generated index.html file.
#
# Prompts the user to install JSDoc if not present. It's not a package.json
# devDependency because it seems that many folks browse JSDoc in their IDE
# without needing to generate the HTML version.
if ! command -v jsdoc > /dev/null; then
echo \"Run 'pnpm add -g jsdoc' to install JSDoc: https://jsdoc.app\"
exit 1
fi
ARGS=()
DESTINATION=""
# Discover the output directory, since JSDoc doesn't have a setting to emit it.
while [[ "$#" -ne 0 ]]; do
curArg="$1"
shift
ARGS+=("$curArg")
case "$curArg" in
-c|--configure)
if [[ -z "$DESTINATION" ]]; then
# All bets are off if the destination property contains an escaped '"' or
# there's more than one "destination" property defined.
DESTINATION="$(sed -ne 's/.*"destination": *"\([^"]*\)".*/\1/p' < "$1")"
fi
ARGS+=("$1")
shift
;;
-d|--destination)
DESTINATION="$1"
ARGS+=("$1")
shift
;;
*)
;;
esac
done
# "out" is the JSDoc default directory.
DESTINATION="${DESTINATION:-out}"
rm -rf "$DESTINATION"
if jsdoc "${ARGS[@]}"; then
exec find "$DESTINATION" -name index.html -print -quit
fi