@@ -71,76 +71,34 @@ DOCBUILD_DIR="${REPO_ROOT}/.docbuild"
7171rm -rf " $DOCBUILD_DIR "
7272mkdir -p " $DOCBUILD_DIR "
7373
74- # Build documentation using xcodebuild docbuild
75- echo " Building documentation with xcodebuild ..."
74+ # Generate documentation using Swift DocC Plugin
75+ echo " Generating documentation with Swift DocC Plugin ..."
7676cd " $REPO_ROOT "
7777
7878# Resolve package dependencies first
7979swift package resolve
8080
81- # Try to build documentation - for Swift packages, we need to open it as a package
82- # First try with an Xcode project if it exists
83- if [ -f " ${PACKAGE_NAME} .xcodeproj/project.pbxproj" ]; then
84- echo " Using existing Xcode project..."
85- BUILD_CMD=" xcodebuild docbuild -scheme ${PACKAGE_NAME} -derivedDataPath ${DOCBUILD_DIR} -destination 'generic/platform=macOS'"
86- elif [ -f " ${PACKAGE_NAME} .xcworkspace/contents.xcworkspacedata" ]; then
87- echo " Using existing Xcode workspace..."
88- BUILD_CMD=" xcodebuild docbuild -workspace ${PACKAGE_NAME} .xcworkspace -scheme ${PACKAGE_NAME} -derivedDataPath ${DOCBUILD_DIR} -destination 'generic/platform=macOS'"
89- else
90- echo " No Xcode project found, generating one..."
91- # Try to generate Xcode project (may not be available in newer Swift versions)
92- swift package generate-xcodeproj 2> /dev/null || {
93- echo " Note: generate-xcodeproj not available, will try opening package directly..."
94- }
95-
96- if [ -f " ${PACKAGE_NAME} .xcodeproj/project.pbxproj" ]; then
97- BUILD_CMD=" xcodebuild docbuild -scheme ${PACKAGE_NAME} -derivedDataPath ${DOCBUILD_DIR} -destination 'generic/platform=macOS'"
98- else
99- # Last resort: try opening the package directory as a project
100- echo " Attempting to build documentation directly from package..."
101- BUILD_CMD=" xcodebuild -resolvePackageDependencies -packagePath ${REPO_ROOT} && xcodebuild docbuild -packagePath ${REPO_ROOT} -derivedDataPath ${DOCBUILD_DIR} -destination 'generic/platform=macOS'"
102- fi
103- fi
104-
105- # Execute the build command
106- if eval " $BUILD_CMD " 2>&1 ; then
107- echo -e " ${GREEN} DocC documentation built successfully${NC} "
108-
109- # Find the .doccarchive
110- DOCS_ARCHIVE=$( find " $DOCBUILD_DIR " -name " *.doccarchive" -type d | head -1)
81+ # Generate documentation using swift package generate-documentation
82+ # This requires the swift-docc-plugin to be added to Package.swift
83+ if swift package --allow-writing-to-directory " $DOCBUILD_DIR " \
84+ generate-documentation \
85+ --target " $PACKAGE_NAME " \
86+ --output-path " $DOCBUILD_DIR " \
87+ --transform-for-static-hosting \
88+ --hosting-base-path " /${PACKAGE_NAME,,} " 2>&1 ; then
89+ echo -e " ${GREEN} DocC documentation generated successfully${NC} "
11190
112- if [ -z " $DOCS_ARCHIVE " ]; then
113- # Try alternative location
114- DOCS_ARCHIVE=$( find " $DOCBUILD_DIR " -name " *.doccarchive" -type d | head -1)
115- fi
91+ # The documentation is already transformed for static hosting in DOCBUILD_DIR
92+ STATIC_DOCS_DIR=" $DOCBUILD_DIR "
11693
117- if [ -n " $DOCS_ARCHIVE " ] && [ -d " $DOCS_ARCHIVE " ]; then
118- echo " Found DocC archive: $DOCS_ARCHIVE "
119-
120- # Transform archive for static hosting
121- STATIC_DOCS_DIR=" ${REPO_ROOT} /.static-docs"
122- rm -rf " $STATIC_DOCS_DIR "
123- mkdir -p " $STATIC_DOCS_DIR "
124-
125- echo " Transforming archive for static hosting..."
126- if command -v docc > /dev/null 2>&1 ; then
127- docc process-archive transform-for-static-hosting \
128- " $DOCS_ARCHIVE " \
129- --output-path " $STATIC_DOCS_DIR " \
130- --hosting-base-path " /${PACKAGE_NAME,,} " || {
131- echo -e " ${YELLOW} Warning: docc transform failed, using archive directly${NC} "
132- STATIC_DOCS_DIR=" $DOCS_ARCHIVE "
133- }
134- else
135- echo -e " ${YELLOW} Warning: docc command not found, using archive directly${NC} "
136- STATIC_DOCS_DIR=" $DOCS_ARCHIVE "
137- fi
94+ if [ -d " $STATIC_DOCS_DIR " ] && [ -n " $( ls -A " $STATIC_DOCS_DIR " 2> /dev/null) " ]; then
95+ echo " Found generated documentation in: $STATIC_DOCS_DIR "
13896 else
139- echo -e " ${YELLOW} DocC archive not found , creating static fallback site${NC} "
97+ echo -e " ${YELLOW} Documentation directory is empty , creating static fallback site${NC} "
14098 STATIC_DOCS_DIR=" "
14199 fi
142100else
143- echo -e " ${YELLOW} xcodebuild docbuild failed, creating static fallback site${NC} "
101+ echo -e " ${YELLOW} swift package generate-documentation failed, creating static fallback site${NC} "
144102 STATIC_DOCS_DIR=" "
145103fi
146104
0 commit comments