forked from trussworks/pre-commit-hooks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpre-commit-gen-docs
executable file
·45 lines (37 loc) · 994 Bytes
/
pre-commit-gen-docs
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
#! /usr/bin/env bash
set -eu -o pipefail
# Get the directory of this file inside pre-commit cache
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
ADR_BIN="${DIR}/../../node_modules/.bin/adr-log"
# Rename ADR to whatever we want
function rename {
perl -i -pe "s/ \[ADR-/ [$1-/g;" index.md
}
# Remove the last line if its an empty newline
function chomp {
perl -pi -e 'chomp if eof;' "$1"
}
function update_index {
pushd "${dir}" > /dev/null || return
# Rebuild the index && remove both newlines that it adds
node "${ADR_BIN}" -i && chomp index.md && chomp index.md
# We need to rename ADR to a different name
title=$(basename "$1")
case "${title}" in
# This is the default behavior
# adr )
# rename ADR ;;
rfc )
rename RFC ;;
runbook )
rename Runbook ;;
how-to )
rename How-To ;;
esac
popd > /dev/null || return
}
for dir in "$@"; do
if [[ -d "${dir}" ]]; then
update_index "${dir}"
fi
done