Skip to content

Instantly share code, notes, and snippets.

@iliaskarim
Created March 25, 2026 11:24
Show Gist options
  • Select an option

  • Save iliaskarim/f0827c4860e97e287cc8b8b17f752ebc to your computer and use it in GitHub Desktop.

Select an option

Save iliaskarim/f0827c4860e97e287cc8b8b17f752ebc to your computer and use it in GitHub Desktop.
#!/bin/bash
set -ex
# toolchain paths – adjust if Xcode is installed elsewhere
DOCC="/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/docc"
# derive scheme name from the current directory (assumes project directory
# name matches the product/scheme name).
SCHEME="$(basename "$(pwd)")"
# when serving from a subpath (e.g. GitHub Pages), use a hosting base path
# default assumes the documentation will live under /<SchemeName> on the
# web server. passing `--no-base` on the command line will disable this
# behavior and omit the flag entirely (resulting in root-relative resource
# links).
HOSTING_BASE_PATH="/$SCHEME"
# simple boolean flag parsing; recognize --no-base to clear the path
while [[ $# -gt 0 ]]; do
case "$1" in
--no-base)
HOSTING_BASE_PATH=""
shift
;;
*)
echo "Unknown argument: $1" >&2
exit 1
;;
esac
done
# clean docs
rm -rf .build build docs
HOSTING_ARGS=()
[ -n "$HOSTING_BASE_PATH" ] && HOSTING_ARGS=(--hosting-base-path "$HOSTING_BASE_PATH")
# build docs
xcodebuild docbuild \
-scheme "$SCHEME" \
-destination 'platform=macOS,arch=arm64,name=My Mac' \
-derivedDataPath build > /dev/null
$DOCC process-archive transform-for-static-hosting \
--output-path ./docs \
"${HOSTING_ARGS[@]}" \
"./build/Build/Products/Debug/$SCHEME.doccarchive" > /dev/null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment