1+ # Build docc documentation
2+
3+ # Arguments:
4+ #
5+ # [-s <path>] Optionally supply a scratch path (a.k.a. build path).
6+ # Defaults to temporary directory, which is unique on every script execution.
7+ # To provide a stable scratch folder, supply this argument with the path to a directory
8+ # (absolute path, or relative path to the current working directory.)
9+ #
10+ # For example, to use the default ".build" folder at the repo's root:
11+ # build-docc -s .build
12+
13+ # Swift-DocC Plugin Documentation:
14+ # https://swiftlang.github.io/swift-docc-plugin/documentation/swiftdoccplugin/
15+
16+ PACKAGE_NAME=" swift-timecode"
17+
18+ usageAndExit () { echo " $0 usage:" && grep " [[:space:]].)\ #" $0 | sed ' s/#//' | sed -r ' s/([a-z])\)/-\1/' ; exit 0; }
19+
20+ while getopts " s::owh" flag; do
21+ case " ${flag} " in
22+ s) # Optionally supply a scratch (build) directory path.
23+ BUILD_PATH=" ${OPTARG} "
24+ ;;
25+ o) # Open folder in the Finder after building.
26+ OPEN_FOLDER_IN_FINDER=1
27+ ;;
28+ w) # Start a local webserver to preview documentation after building.
29+ ALLOW_WEBSERVER=1
30+ ;;
31+ h) # Display help.
32+ usageAndExit
33+ ;;
34+ esac
35+ done
36+
37+ # Provide default(s) for arguments
38+ if [ " $OPEN_FOLDER_IN_FINDER " = " " ]; then OPEN_FOLDER_IN_FINDER=0; fi
39+ if [ " $ALLOW_WEBSERVER " = " " ]; then ALLOW_WEBSERVER=0; fi
40+
41+ # Set up base paths
42+ REPO_PATH=" $( git rev-parse --show-toplevel) "
43+ TEMP_WORKING_PATH=" $( mktemp -d) "
44+ DOCC_OUTPUT_WEBROOT=" $TEMP_WORKING_PATH /docs-webroot"
45+ DOCC_OUTPUT_PATH=" $DOCC_OUTPUT_WEBROOT /$PACKAGE_NAME "
46+
47+ echo " Package Name: $PACKAGE_NAME "
48+ echo " Repo Path: $REPO_PATH "
49+ echo " Temporary Working Path: $TEMP_WORKING_PATH "
50+ echo " DocC Output Path: $DOCC_OUTPUT_PATH "
51+
52+ # Create output folders
53+ mkdir " $DOCC_OUTPUT_WEBROOT "
54+ mkdir " $DOCC_OUTPUT_PATH "
55+
56+ cd " $REPO_PATH "
57+
58+ # Set up build paths
59+ if [ " $BUILD_PATH " = " " ]; then BUILD_PATH=" $TEMP_WORKING_PATH /build" ; fi
60+ echo " Scratch (Build) Path: $BUILD_PATH "
61+ PLUGIN_OUTPUTS_PATH=" $BUILD_PATH /plugins/Swift-DocC/outputs"
62+
63+ # Delete old docs from build folder, if any
64+ if [ -d " $PLUGIN_OUTPUTS_PATH " ]; then
65+ echo " Removing old build products..."
66+ rm -r " $PLUGIN_OUTPUTS_PATH "
67+ fi
68+
69+ # Custom env flag that opts-in to using the plugin as a Package dependency
70+ export ENABLE_DOCC_PLUGIN=1
71+
72+ # --disable-indexing: Indexing is only relevant to IDEs like Xcode, and not relevant for hosting online
73+ echo " Compiling docs..."
74+ swift package \
75+ --scratch-path " $BUILD_PATH " \
76+ --disable-sandbox \
77+ --allow-writing-to-directory " $DOCC_OUTPUT_PATH " \
78+ generate-documentation \
79+ --target SwiftTimecode \
80+ --target SwiftTimecodeAV \
81+ --target SwiftTimecodeCore \
82+ --target SwiftTimecodeUI \
83+ --disable-indexing \
84+ --output-path " $DOCC_OUTPUT_PATH " \
85+ --transform-for-static-hosting \
86+ --enable-experimental-combined-documentation \
87+ --hosting-base-path " $PACKAGE_NAME "
88+
89+ # Reveal output folder in finder
90+ if [ $OPEN_FOLDER_IN_FINDER == 1 ]; then
91+ echo " Opening built documentation in Finder."
92+ open " $DOCC_OUTPUT_PATH "
93+ fi
94+
95+ # Start local webserver
96+ if [ $ALLOW_WEBSERVER == 1 ]; then
97+ echo Starting localhost webserver on port 8080. Press Ctrl+C to end.
98+ echo Browse: http://localhost:8080/$PACKAGE_NAME /documentation/
99+ cd " $DOCC_OUTPUT_WEBROOT "
100+ ruby -run -ehttpd . -p8080
101+ fi
0 commit comments