-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate
executable file
·99 lines (78 loc) · 2.68 KB
/
generate
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
#!/bin/sh
set -eo pipefail
repo_path="https://github.com/libgit2/libgit2"
source_path=$(mktemp -d)
verbose=true
force=
if [ "$1" = "" ]; then
echo "usage: $0 output_path" 1>&2
exit 1
fi
output_path=$1
function do_checkout {
if [ "$1" = "" ]; then
echo "usage: $0 source_path" 1>&2
exit 1
fi
if [ "${verbose}" ]; then
echo ":: Checking out source trees..."
echo ""
fi
source_path=$1
mkdir -p "${source_path}"
git clone "${repo_path}" "${source_path}/main" --no-checkout
( cd "${source_path}/main" && git sparse-checkout set --no-cone 'include/*' )
( cd "${source_path}/main" && git read-tree main )
( cd "${source_path}/main" && git checkout -- include )
for tag in $(git --git-dir="${source_path}/main/.git" tag -l); do
git --git-dir="${source_path}/main/.git" worktree add -f "${source_path}/${tag}" "${tag}" --no-checkout
( cd "${source_path}/${tag}" && git sparse-checkout set --no-cone 'include/*' )
( cd "${source_path}/${tag}" && git read-tree HEAD )
if [ "${tag}" == "v0.1.0" ]; then
( cd "${source_path}/${tag}" && git checkout -- src/git )
elif [ "${tag}" == "v0.2.0" -o "${tag}" == "v0.3.0" ]; then
( cd "${source_path}/${tag}" && git checkout -- src/git2 )
else
( cd "${source_path}/${tag}" && git checkout -- include )
fi
done
}
do_checkout ${source_path}
if [ "${verbose}" ]; then
echo ""
echo ":: Generating raw API documentation..."
echo ""
fi
for version in ${source_path}/*; do
version=$(echo "${version}" | sed -e "s/.*\///")
commit=$( cd "${source_path}/${version}" && git rev-parse HEAD )
if [ -f "${output_path}/api/${version}.json" ]; then
existing_commit=$(jq -r .info.commit < "${output_path}/api/${version}.json")
if [ "${existing_commit}" == "${commit}" -a ! "${force}" ]; then
if [ "${verbose}" ]; then
echo "Raw API documentation for ${version} exists; skipping..."
fi
continue
fi
fi
options=""
if [ "${force}" ]; then
options="${options} --force"
fi
echo "Generating raw API documentation for ${version}..."
mkdir -p "${output_path}/api"
node ./header_parser $options "${source_path}/${version}" > "${output_path}/api/${version}.json"
done
if [ "${verbose}" ]; then
echo ""
echo ":: Generating HTML documentation..."
echo ""
fi
options=""
if [ "${verbose}" ]; then
options="${options} --verbose"
fi
if [ "${force}" ]; then
options="${options} --force"
fi
node ./docs-generator.js --verbose --jekyll-layout default "${output_path}/api" "${output_path}/reference"