@@ -94,7 +94,7 @@ log_error() {
9494# Function to run docc command
9595rundocc () {
9696 if command -v xcrun > /dev/null 2>&1 ; then
97- xcrun docc " $@ "
97+ DOCC_HTML_DIR= " /Users/kyle/tmp/Doc/swift-docc-render/dist " xcrun docc " $@ "
9898 else
9999 docc " $@ "
100100 fi
@@ -334,115 +334,141 @@ fi
334334log_info " Building documentation archive..."
335335
336336if [[ -n " $DOCC_CATALOG " ]]; then
337- # We have a .docc catalog
338337 DOCC_ARGS=(
339338 " $DOCC_CATALOG "
340- --output-path " $DOCC_OUTPUT_DIR "
341339 --emit-digest
342340 --transform-for-static-hosting
341+ --output-path " $DOCC_OUTPUT_DIR "
343342 )
344343
344+ if [[ " $PREVIEW_MODE " == true ]]; then
345+ DOCC_ARGS+=(--port " $PREVIEW_PORT " )
346+ fi
347+
345348 if [[ -n " $HOSTING_BASE_PATH " ]]; then
346349 DOCC_ARGS+=(--hosting-base-path " $HOSTING_BASE_PATH " )
347350 fi
348351
349- # Add source service configuration
350352 if [[ -n " $SOURCE_SERVICE " ]]; then
351353 DOCC_ARGS+=(--source-service " $SOURCE_SERVICE " )
352354 DOCC_ARGS+=(--source-service-base-url " $SOURCE_SERVICE_BASE_URL " )
353355 DOCC_ARGS+=(--checkout-path " $REPO_ROOT " )
354356 fi
355357
356- # Add symbol graph directory if we have symbol graphs
357358 if [[ -d " $SYMBOL_GRAPH_DIR " ]] && [[ -n " $( ls -A " $SYMBOL_GRAPH_DIR " ) " ]]; then
358359 DOCC_ARGS+=(--additional-symbol-graph-dir " $SYMBOL_GRAPH_DIR " )
359360 fi
360361
361- rundocc convert " ${DOCC_ARGS[@]} "
362+ if [[ " $PREVIEW_MODE " == true ]]; then
363+ # Check if port is already in use
364+ if lsof -Pi :$PREVIEW_PORT -sTCP:LISTEN -t > /dev/null 2>&1 ; then
365+ log_warning " Port $PREVIEW_PORT is already in use"
366+
367+ # Find the process using the port
368+ PORT_PID=$( lsof -Pi :$PREVIEW_PORT -sTCP:LISTEN -t)
369+ PORT_PROCESS=$( ps -p $PORT_PID -o command= 2> /dev/null || echo " Unknown process" )
370+
371+ log_info " Process using port $PREVIEW_PORT (PID $PORT_PID ): $PORT_PROCESS "
372+
373+ # Ask user if they want to kill it
374+ read -p " Do you want to kill this process and start the preview server? (y/N): " -n 1 -r
375+ echo
376+
377+ if [[ $REPLY =~ ^[Yy]$ ]]; then
378+ log_info " Killing process $PORT_PID ..."
379+ kill $PORT_PID
380+ sleep 1
381+
382+ # Verify it's killed
383+ if lsof -Pi :$PREVIEW_PORT -sTCP:LISTEN -t > /dev/null 2>&1 ; then
384+ log_error " Failed to kill process on port $PREVIEW_PORT "
385+ exit 1
386+ fi
387+ log_info " Process killed successfully"
388+ else
389+ log_error " Cannot start preview server. Please free port $PREVIEW_PORT or use --port option"
390+ exit 1
391+ fi
392+ fi
393+
394+ log_info " Starting documentation preview server on port $PREVIEW_PORT ..."
395+ log_info " Press Ctrl+C to stop the server"
396+ rundocc preview " ${DOCC_ARGS[@]} "
397+ else
398+ rundocc convert " ${DOCC_ARGS[@]} "
399+ fi
362400else
363- # No .docc catalog, create one from symbol graphs
364401 TEMP_DOCC_CATALOG=" $BUILD_DIR /${TARGET_NAME} .docc"
365402 mkdir -p " $TEMP_DOCC_CATALOG "
366403
367- # Copy symbol graphs into the catalog
368404 if [[ -d " $SYMBOL_GRAPH_DIR " ]] && [[ -n " $( ls -A " $SYMBOL_GRAPH_DIR " ) " ]]; then
369405 cp " $SYMBOL_GRAPH_DIR " /* .symbols.json " $TEMP_DOCC_CATALOG /"
370406 fi
371407
372408 DOCC_ARGS=(
373409 " $TEMP_DOCC_CATALOG "
374- --output-path " $DOCC_OUTPUT_DIR "
375410 --emit-digest
376411 --transform-for-static-hosting
412+ --output-path " $DOCC_OUTPUT_DIR "
377413 )
378414
415+ if [[ " $PREVIEW_MODE " == true ]]; then
416+ DOCC_ARGS+=(--port " $PREVIEW_PORT " )
417+ fi
418+
379419 if [[ -n " $HOSTING_BASE_PATH " ]]; then
380420 DOCC_ARGS+=(--hosting-base-path " $HOSTING_BASE_PATH " )
381421 fi
382422
383- # Add source service configuration
384423 if [[ -n " $SOURCE_SERVICE " ]]; then
385424 DOCC_ARGS+=(--source-service " $SOURCE_SERVICE " )
386425 DOCC_ARGS+=(--source-service-base-url " $SOURCE_SERVICE_BASE_URL " )
387426 DOCC_ARGS+=(--checkout-path " $REPO_ROOT " )
388427 fi
389428
390- rundocc convert " ${DOCC_ARGS[@]} "
391- fi
392-
393- log_info " Documentation built successfully"
394- log_info " Documentation output: $DOCC_OUTPUT_DIR "
395-
396- # Step 4: Preview if requested
397- if [[ " $PREVIEW_MODE " == true ]]; then
398- # Check if port is already in use
399- if lsof -Pi :$PREVIEW_PORT -sTCP:LISTEN -t > /dev/null 2>&1 ; then
400- log_warning " Port $PREVIEW_PORT is already in use"
401-
402- # Find the process using the port
403- PORT_PID=$( lsof -Pi :$PREVIEW_PORT -sTCP:LISTEN -t)
404- PORT_PROCESS=$( ps -p $PORT_PID -o command= 2> /dev/null || echo " Unknown process" )
405-
406- log_info " Process using port $PREVIEW_PORT (PID $PORT_PID ): $PORT_PROCESS "
407-
408- # Ask user if they want to kill it
409- read -p " Do you want to kill this process and start the preview server? (y/N): " -n 1 -r
410- echo
411-
412- if [[ $REPLY =~ ^[Yy]$ ]]; then
413- log_info " Killing process $PORT_PID ..."
414- kill $PORT_PID
415- sleep 1
416-
417- # Verify it's killed
418- if lsof -Pi :$PREVIEW_PORT -sTCP:LISTEN -t > /dev/null 2>&1 ; then
419- log_error " Failed to kill process on port $PREVIEW_PORT "
429+ if [[ " $PREVIEW_MODE " == true ]]; then
430+ # Check if port is already in use
431+ if lsof -Pi :$PREVIEW_PORT -sTCP:LISTEN -t > /dev/null 2>&1 ; then
432+ log_warning " Port $PREVIEW_PORT is already in use"
433+
434+ # Find the process using the port
435+ PORT_PID=$( lsof -Pi :$PREVIEW_PORT -sTCP:LISTEN -t)
436+ PORT_PROCESS=$( ps -p $PORT_PID -o command= 2> /dev/null || echo " Unknown process" )
437+
438+ log_info " Process using port $PREVIEW_PORT (PID $PORT_PID ): $PORT_PROCESS "
439+
440+ # Ask user if they want to kill it
441+ read -p " Do you want to kill this process and start the preview server? (y/N): " -n 1 -r
442+ echo
443+
444+ if [[ $REPLY =~ ^[Yy]$ ]]; then
445+ log_info " Killing process $PORT_PID ..."
446+ kill $PORT_PID
447+ sleep 1
448+
449+ # Verify it's killed
450+ if lsof -Pi :$PREVIEW_PORT -sTCP:LISTEN -t > /dev/null 2>&1 ; then
451+ log_error " Failed to kill process on port $PREVIEW_PORT "
452+ exit 1
453+ fi
454+ log_info " Process killed successfully"
455+ else
456+ log_error " Cannot start preview server. Please free port $PREVIEW_PORT or use --port option"
420457 exit 1
421458 fi
422- log_info " Process killed successfully"
423- else
424- log_error " Cannot start preview server. Please free port $PREVIEW_PORT or use --port option"
425- exit 1
426459 fi
427- fi
428460
429- # Detect the actual module name from the generated documentation
430- ACTUAL_MODULE=" "
431- if [[ -d " $DOCC_OUTPUT_DIR /data/documentation" ]]; then
432- # Find the first .json file in data/documentation directory
433- ACTUAL_MODULE=$( ls " $DOCC_OUTPUT_DIR /data/documentation" /* .json 2> /dev/null | head -1 | xargs basename -s .json)
434- fi
435-
436- log_info " Starting preview server on port $PREVIEW_PORT ..."
437- if [[ -n " $ACTUAL_MODULE " ]]; then
438- log_info " Documentation will be available at: http://localhost:$PREVIEW_PORT /documentation/$ACTUAL_MODULE "
461+ log_info " Starting documentation preview server on port $PREVIEW_PORT ..."
462+ log_info " Press Ctrl+C to stop the server"
463+ rundocc preview " ${DOCC_ARGS[@]} "
439464 else
440- log_info " Documentation will be available at: http://localhost: $PREVIEW_PORT / "
465+ rundocc convert " ${DOCC_ARGS[@]} "
441466 fi
442- log_info " Press Ctrl+C to stop the server "
467+ fi
443468
444- cd " $DOCC_OUTPUT_DIR "
445- python3 -m http.server $PREVIEW_PORT
469+ if [[ " $PREVIEW_MODE " == false ]]; then
470+ log_info " Documentation built successfully"
471+ log_info " Documentation output: $DOCC_OUTPUT_DIR "
446472fi
447473
448474log_info " Done!"
0 commit comments