-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
87a3a6e
commit 9b0b991
Showing
2 changed files
with
87 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
#!/bin/bash | ||
|
||
if [ ! -d spec ] | ||
then | ||
echo "Error: spec folder not found" | ||
echo " run this script from the root of repo" | ||
exit 1 | ||
fi | ||
|
||
tmpdir=scripts/tmp | ||
mkdir -p scripts/tmp | ||
|
||
arg_generate_docs=0 | ||
|
||
for arg in "$@" | ||
do | ||
if [ "$arg" == "--fix" ] || [ "$arg" == "--generate-docs" ] | ||
then | ||
arg_generate_docs=1 | ||
else | ||
echo "usage: ./scripts/update_docs_index.sh [--fix]" | ||
exit 1 | ||
fi | ||
done | ||
|
||
function print_hooks() { | ||
local version="$1" | ||
local hook | ||
local hook_slug | ||
while read -r hook | ||
do | ||
hook_slug="${hook%%(*}" | ||
echo "" | ||
echo "[#$hook](classes/TeeworldsClient.md#$hook_slug)" | ||
done < <(grep '###' "docs/$version/classes/TeeworldsClient.md" | cut -d'#' -f5) | ||
} | ||
|
||
function gen_doc_index() { | ||
local version="$1" | ||
local index_file="docs/$version/README.md" | ||
if [ ! -f "$index_file" ] | ||
then | ||
echo "Error: missing index file $index_file" | ||
exit 1 | ||
fi | ||
local tmpfile="$tmpdir/README.md" | ||
{ | ||
awk '1;/TeeworldsClient/{exit}' "$index_file" | ||
print_hooks "$version" | ||
} > "$tmpfile" | ||
if [ "$arg_generate_docs" == "1" ] | ||
then | ||
mv "$tmpfile" "$index_file" | ||
return | ||
fi | ||
local diff="$(diff "$tmpfile" "$index_file")" | ||
if [ "$diff" != "" ] | ||
then | ||
echo "Error: documentation index is not up to date" | ||
echo " to fix this run ./scripts/update_docs_index.sh --fix" | ||
echo "" | ||
echo "$diff" | ||
exit 1 | ||
fi | ||
} | ||
|
||
function main() { | ||
local version | ||
version="$(grep TEEWORLDS_NETWORK_VERSION lib/version.rb | cut -d"'" -f2)" | ||
if [ "$version" == "" ] | ||
then | ||
echo "Error: failed to get library version" | ||
exit 1 | ||
fi | ||
gen_doc_index "$version" | ||
} | ||
|
||
main |