Skip to content

Commit d80a225

Browse files
Added generator.sh
1 parent 0aaead9 commit d80a225

File tree

1 file changed

+99
-0
lines changed

1 file changed

+99
-0
lines changed

generate.sh

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
#!/bin/sh
2+
# WooCommerce Class API docs generator
3+
4+
# Variables
5+
GENERATOR_VERSION="0.0.1"
6+
WOOCOMMERCE_VERSION=""
7+
8+
# Output colorized strings
9+
#
10+
# Color codes:
11+
# 0 - black
12+
# 1 - red
13+
# 2 - green
14+
# 3 - yellow
15+
# 4 - blue
16+
# 5 - magenta
17+
# 6 - cian
18+
# 7 - white
19+
output() {
20+
echo "$(tput setaf "$1")$2$(tput sgr0)"
21+
}
22+
23+
# Output error message.
24+
help_output() {
25+
echo "Usage: ./generate.sh [options]"
26+
echo
27+
echo "Generate WooCommerce Class API docs."
28+
echo
29+
echo "Examples:"
30+
echo "./generate.sh -w 3.6.5"
31+
echo
32+
echo "Available options:"
33+
echo " -h [--help] Shows help message"
34+
echo " -v [--version] Shows generator version"
35+
echo " -w [--woocommerce] WooCommerce version"
36+
}
37+
38+
output 5 "-------------------------------------------"
39+
output 5 " WOOCOMMERCE CLASS API DOCS GENERATOR "
40+
output 5 "-------------------------------------------"
41+
42+
# Display help message when no option is used.
43+
if [ -z "$1" ]; then
44+
help_output
45+
fi
46+
47+
# Set user options
48+
while [ ! $# -eq 0 ]; do
49+
case "$1" in
50+
-h|--help)
51+
help_output
52+
exit 0
53+
;;
54+
-v|--version)
55+
echo "Version ${GENERATOR_VERSION}"
56+
exit 0
57+
;;
58+
-w|--woocommerce)
59+
WOOCOMMERCE_VERSION="${2}"
60+
shift
61+
;;
62+
*)
63+
output 1 "\"${1}\" is not a valid command. See \"./generate.sh --help\"."
64+
exit 1;
65+
;;
66+
esac
67+
shift
68+
done
69+
70+
# Start generation
71+
output 2 "Starting generation process..."
72+
echo
73+
74+
# Bootstrap
75+
rm -rf ./build ./source
76+
mkdir -p ./build ./source
77+
78+
# Install composer packges in case is missing
79+
if [ ! -f "vendor/bin/apigen" ]; then
80+
output 1 "Composer packages not installed!"
81+
output 2 "Installing composer packages..."
82+
composer install
83+
fi
84+
85+
# Clone WooCommerce
86+
output 2 "Cloning WooCommerce ${WOOCOMMERCE_VERSION}..."
87+
echo
88+
git clone --no-checkout --single-branch --depth 1 --branch "${WOOCOMMERCE_VERSION}" https://github.com/woocommerce/woocommerce.git source/woocommerce
89+
90+
# Generate docs
91+
echo
92+
output 2 "Generating API docs..."
93+
echo
94+
./vendor/bin/apigen generate -q
95+
php apigen/hook-docs.php
96+
97+
# Done
98+
echo
99+
output 2 "API docs generated successfully!"

0 commit comments

Comments
 (0)