Skip to content

Commit

Permalink
Change api docs versioning directory input and output logic
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffdgr8 committed Dec 22, 2024
1 parent af4ec9f commit 4694985
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,39 +26,37 @@ allprojects {
tasks.dokkaGeneratePublicationHtml {
val apiDocsDir = projectDir.resolve("docs/api")
val olderDir = apiDocsDir.resolve("older")
val tempOlderDir = apiDocsDir.parentFile.resolve("older")
tempOlderDir.mkdir()

val shortVersion = """\d+\.\d+""".toRegex()
.find(version.toString())!!
.groupValues.first()

doFirst {
olderDir.renameTo(tempOlderDir)
dokka.pluginsConfiguration.versioning {
olderVersionsDir = olderDir
version = shortVersion
}

doFirst {
val versionJson = apiDocsDir.resolve("version.json")
if (versionJson.exists()) {
val currentDocsVersion = """"version"\s*:\s*"(\d+\.\d+)"""".toRegex()
.find(versionJson.readText())!!
.groupValues[1]

if (currentDocsVersion != shortVersion) {
val tempOlderDir = apiDocsDir.parentFile.resolve("older")
olderDir.renameTo(tempOlderDir)
val archiveDir = tempOlderDir.resolve(currentDocsVersion)
apiDocsDir.renameTo(archiveDir)
apiDocsDir.mkdir()
tempOlderDir.renameTo(olderDir)
}
}

apiDocsDir.deleteRecursively()
}
outputDirectory.set(apiDocsDir)

dokka.pluginsConfiguration.versioning {
olderVersionsDir = tempOlderDir
version = shortVersion
}

doLast {
tempOlderDir.deleteRecursively()
apiDocsDir.deleteRecursively()
outputDirectory.get().asFile.renameTo(apiDocsDir)
}
}

Expand Down

0 comments on commit 4694985

Please sign in to comment.