-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbuild-asciidocs.sh
More file actions
executable file
·85 lines (69 loc) · 2.2 KB
/
build-asciidocs.sh
File metadata and controls
executable file
·85 lines (69 loc) · 2.2 KB
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
#!/usr/bin/env bash
function clearDir() {
if [ -d "$1" ]; then
echo "Clearing dir: $1"
# shellcheck disable=SC2115
rm -rf "$1/"
fi
}
function cleanDocsDir() {
if [ -d "$1" ]; then
echo "Clearing docs dir: $1"
find "$1" ! -name '_index.html' -type f -exec rm -f {} +
else
echo "Creating doc dir: $1"
mkdir -p "$1"
fi
}
function createIndex() {
cd "$1" || exit 2;
if [ ! -f "_index.html" ]; then
echo $'---\n---' > _index.html
fi
}
# get script arguments
set -x
args="$@"
echo $args
# no input, so just exit
if [ ! -n "$args" ]; then
echo "Usage: build-asciidocs.sh git-branch-1 git-branch-2"
exit 1
fi
# change dir to one with this script
cd "$( dirname "${BASH_SOURCE[0]}" )" || exit 2
BASE_DIR=`pwd` # base project dir
echo "Working dir: $BASE_DIR"
# init and check paths
ASCII_DOC_DIR="$BASE_DIR/content/docs" # Asciidoc goes to content, Hugo will process it
AGREST_TMP_DIR="$BASE_DIR/target/tmp" # tmp directory to checkout Agrest
# prepare all directories
clearDir "$AGREST_TMP_DIR"
cleanDocsDir "$ASCII_DOC_DIR"
for git_tag in ${args[@]}
do
# clone git repo and checkout requested TAG
AGREST_TMP_DIR_VERSION="$BASE_DIR/target/tmp/$git_tag" # tmp directory with defined version to checkout Agrest
GIT_TAG="$git_tag"
git clone https://github.com/agrestio/agrest-docs.git "$AGREST_TMP_DIR_VERSION" --branch "$GIT_TAG" || ( echo "Wrong branch : $GIT_TAG" && exit 2)
cd "$AGREST_TMP_DIR_VERSION/" || exit 2
# build it
echo "Running Maven build... it can take a while..."
mvn package -q -B -DskipTests > /dev/null 2>&1
echo "Maven build complete"
# copy everything from ./target/tmp/**/target/site/** directories
for d in */ ; do
# skip asciidoc extension module
if [ "$d" == "agrest-asciidoc-postprocessor/" ]; then
continue
fi
echo "Syncing asciidoc content for ${d}"
ASCII_DOC_DIR_VERSION="$ASCII_DOC_DIR/$GIT_TAG"
checkAndCreateDir "$ASCII_DOC_DIR_VERSION"
cp -R "./${d}target/site/." "$ASCII_DOC_DIR_VERSION/" || exit 2
done
# create _index.html for list.html
createIndex "$ASCII_DOC_DIR_VERSION"
done
# create _index.html for list.html
createIndex "$ASCII_DOC_DIR"