@@ -19,9 +19,9 @@ import java.io.IOException
19
19
import java.net.URI
20
20
import java.nio.file.Path
21
21
import kotlin.io.path.createSymbolicLinkPointingTo
22
- import kotlin.io.path.deleteIfExists
23
22
import kotlin.io.path.exists
24
23
import kotlin.io.path.isSameFileAs
24
+ import org.pkl.commons.copyRecursively
25
25
import org.pkl.commons.deleteRecursively
26
26
import org.pkl.core.ModuleSchema
27
27
import org.pkl.core.PClassInfo
@@ -53,6 +53,7 @@ class DocGenerator(
53
53
54
54
/* * A comparator for package versions. */
55
55
versionComparator : Comparator <String >,
56
+
56
57
/* * The directory where generated documentation is placed. */
57
58
private val outputDir : Path ,
58
59
@@ -62,9 +63,20 @@ class DocGenerator(
62
63
* Generates source URLs with fixed line numbers `#L123-L456` to avoid churn in expected output
63
64
* files (e.g., when stdlib line numbers change).
64
65
*/
65
- private val isTestMode : Boolean = false
66
+ private val isTestMode : Boolean = false ,
67
+
68
+ /* *
69
+ * Determines how to create the "current" directory which contains documentation for the latest
70
+ * version of the package.
71
+ *
72
+ * [CurrentDirectoryMode.SYMLINK] will make the current directory into a symlink to the actual
73
+ * version directory. [CurrentDirectoryMode.COPY], however, will create a full copy instead.
74
+ */
75
+ private val currentDirectoryMode : CurrentDirectoryMode = CurrentDirectoryMode .SYMLINK
66
76
) {
67
77
companion object {
78
+ const val CURRENT_DIRECTORY_NAME = " current"
79
+
68
80
internal fun List<PackageData>.current (
69
81
versionComparator : Comparator <String >
70
82
): List <PackageData > {
@@ -105,7 +117,7 @@ class DocGenerator(
105
117
val packagesData = packageDataGenerator.readAll()
106
118
val currentPackagesData = packagesData.current(descendingVersionComparator)
107
119
108
- createSymlinks (currentPackagesData)
120
+ createCurrentDirectories (currentPackagesData)
109
121
110
122
htmlGenerator.generateSite(currentPackagesData)
111
123
searchIndexGenerator.generateSiteIndex(currentPackagesData)
@@ -120,16 +132,42 @@ class DocGenerator(
120
132
outputDir.resolve(" $name /$version " ).deleteRecursively()
121
133
}
122
134
123
- private fun createSymlinks (currentPackagesData : List <PackageData >) {
135
+ private fun createCurrentDirectories (currentPackagesData : List <PackageData >) {
124
136
for (packageData in currentPackagesData) {
125
137
val basePath = outputDir.resolve(packageData.ref.pkg.pathEncoded)
126
138
val src = basePath.resolve(packageData.ref.version)
127
- val dest = basePath.resolve(" current" )
128
- if (dest.exists() && dest.isSameFileAs(src)) continue
129
- dest.deleteIfExists()
130
- dest.createSymbolicLinkPointingTo(IoUtils .relativize(src, basePath))
139
+ val dst = basePath.resolve(CURRENT_DIRECTORY_NAME )
140
+
141
+ when (currentDirectoryMode) {
142
+ CurrentDirectoryMode .SYMLINK -> {
143
+ if (! dst.exists() || ! dst.isSameFileAs(src)) {
144
+ dst.deleteRecursively()
145
+ dst.createSymbolicLinkPointingTo(IoUtils .relativize(src, basePath))
146
+ }
147
+ }
148
+ CurrentDirectoryMode .COPY -> {
149
+ dst.deleteRecursively()
150
+ src.copyRecursively(dst)
151
+ }
152
+ }
131
153
}
132
154
}
155
+
156
+ /* *
157
+ * Determines how to create the "current" directory with the contents of the latest generated
158
+ * version of the package docs.
159
+ */
160
+ enum class CurrentDirectoryMode {
161
+ /* *
162
+ * Create a symlink pointing to the directory with the latest version of documentation.
163
+ */
164
+ SYMLINK ,
165
+
166
+ /* *
167
+ * Make a full copy of the directory with the latest version of documentation.
168
+ */
169
+ COPY
170
+ }
133
171
}
134
172
135
173
internal class DocPackage (val docPackageInfo : DocPackageInfo , val modules : List <ModuleSchema >) {
0 commit comments