@@ -12,20 +12,23 @@ show_usage() {
1212 echo " This script builds DocC for a <TARGET> and certain <PLATFORMS>."
1313
1414 echo
15- echo " Usage: $0 [TARGET] [-p|--platforms <PLATFORM1> <PLATFORM2> ...]"
15+ echo " Usage: $0 [TARGET] [-p|--platforms <PLATFORM1> <PLATFORM2> ...] [--hosting-base-path <PATH>] "
1616 echo " [TARGET] Optional. The target to build documentation for (defaults to package name)"
1717 echo " -p, --platforms Optional. List of platforms (default: iOS macOS tvOS watchOS xrOS)"
18-
18+ echo " --hosting-base-path Optional. Base path for static hosting (default: TARGET name, use empty string \"\" for root)"
19+
1920 echo
2021 echo " The documentation ends up in .build/docs-<PLATFORM>."
21-
22+
2223 echo
2324 echo " Examples:"
2425 echo " $0 "
2526 echo " $0 MyTarget"
2627 echo " $0 -p iOS macOS"
2728 echo " $0 MyTarget -p iOS macOS"
2829 echo " $0 MyTarget --platforms iOS macOS tvOS watchOS xrOS"
30+ echo " $0 MyTarget --hosting-base-path \"\" "
31+ echo " $0 MyTarget --hosting-base-path \" custom/path\" "
2932 echo
3033}
3134
@@ -41,26 +44,35 @@ show_error_and_exit() {
4144# Define argument variables
4245TARGET=" "
4346PLATFORMS=" iOS macOS tvOS watchOS xrOS" # Default platforms
47+ HOSTING_BASE_PATH=" " # Will be set to TARGET if not specified
4448
4549# Parse command line arguments
4650while [[ $# -gt 0 ]]; do
4751 case $1 in
4852 -p|--platforms)
4953 shift # Remove --platforms from arguments
5054 PLATFORMS=" " # Clear default platforms
51-
55+
5256 # Collect all platform arguments until we hit another flag or run out of args
5357 while [[ $# -gt 0 && ! " $1 " =~ ^- ]]; do
5458 PLATFORMS=" $PLATFORMS $1 "
5559 shift
5660 done
57-
61+
5862 # Remove leading space and check if we got any platforms
5963 PLATFORMS=$( echo " $PLATFORMS " | sed ' s/^ *//' )
6064 if [ -z " $PLATFORMS " ]; then
6165 show_error_and_exit " --platforms requires at least one platform"
6266 fi
6367 ;;
68+ --hosting-base-path)
69+ shift # Remove --hosting-base-path from arguments
70+ if [[ $# -eq 0 ]]; then
71+ show_error_and_exit " --hosting-base-path requires a value (use \"\" for empty path)"
72+ fi
73+ HOSTING_BASE_PATH=" $1 "
74+ shift
75+ ;;
6476 -h|--help)
6577 show_usage; exit 0 ;;
6678 -* )
@@ -81,7 +93,7 @@ if [ -z "$TARGET" ]; then
8193 # Use the script folder to refer to other scripts
8294 FOLDER=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " & > /dev/null && pwd ) "
8395 SCRIPT_PACKAGE_NAME=" $FOLDER /package_name.sh"
84-
96+
8597 # Check if package_name.sh exists
8698 if [ -f " $SCRIPT_PACKAGE_NAME " ]; then
8799 echo " No target provided, attempting to get package name..."
@@ -103,6 +115,11 @@ if [ -z "$TARGET" ]; then
103115 fi
104116fi
105117
118+ # Set default hosting base path if not specified
119+ if [ -z " $HOSTING_BASE_PATH " ] && [ " $HOSTING_BASE_PATH " != " " ]; then
120+ HOSTING_BASE_PATH=" $TARGET "
121+ fi
122+
106123# Define target lowercase for redirect script
107124TARGET_LOWERCASED=$( echo " $TARGET " | tr ' [:upper:]' ' [:lower:]' )
108125
@@ -145,11 +162,18 @@ build_platform() {
145162 return 1
146163 fi
147164
148- # Transform docs for static hosting
149- if ! $( xcrun --find docc) process-archive \
150- transform-for-static-hosting .build/docbuild/Build/Products/$DEBUG_PATH /$TARGET .doccarchive \
151- --output-path .build/docs-$PLATFORM \
152- --hosting-base-path " $TARGET " ; then
165+ # Transform docs for static hosting with configurable base path
166+ local DOCC_COMMAND=" $( xcrun --find docc) process-archive transform-for-static-hosting .build/docbuild/Build/Products/$DEBUG_PATH /$TARGET .doccarchive --output-path .build/docs-$PLATFORM "
167+
168+ # Add hosting-base-path only if it's not empty
169+ if [ -n " $HOSTING_BASE_PATH " ]; then
170+ DOCC_COMMAND=" $DOCC_COMMAND --hosting-base-path \" $HOSTING_BASE_PATH \" "
171+ echo " Using hosting base path: '$HOSTING_BASE_PATH '"
172+ else
173+ echo " Using empty hosting base path (root level)"
174+ fi
175+
176+ if ! eval " $DOCC_COMMAND " ; then
153177 echo " Failed to transform documentation for $PLATFORM "
154178 return 1
155179 fi
@@ -164,6 +188,11 @@ build_platform() {
164188# Start script
165189echo
166190echo " Building $TARGET docs for [$PLATFORMS ]..."
191+ if [ -n " $HOSTING_BASE_PATH " ]; then
192+ echo " Hosting base path: '$HOSTING_BASE_PATH '"
193+ else
194+ echo " Hosting base path: (empty - root level)"
195+ fi
167196
168197# Loop through all platforms and call the build function
169198for PLATFORM in $PLATFORMS ; do
175204# Complete successfully
176205echo
177206echo " Building $TARGET docs completed successfully!"
178- echo
207+ echo
0 commit comments