Skip to content

Commit 4c2c13b

Browse files
initial api ref
1 parent ad5e6b3 commit 4c2c13b

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed

build.gradle.kts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
import com.sun.net.httpserver.HttpExchange
2+
import com.sun.net.httpserver.HttpServer
3+
import java.net.InetSocketAddress
4+
import java.net.URLDecoder
5+
import java.nio.file.Files
6+
17
plugins {
28
alias(libs.plugins.jetbrainsCompose) apply false
39
alias(libs.plugins.compose.compiler) apply false
@@ -16,6 +22,7 @@ plugins {
1622
alias(libs.plugins.kotlinter) apply false
1723
alias(libs.plugins.keeper) apply false
1824
alias(libs.plugins.kotlin.atomicfu) apply false
25+
id("org.jetbrains.dokka") version "2.0.0"
1926
}
2027

2128
allprojects {
@@ -57,3 +64,41 @@ subprojects {
5764
tasks.register<Delete>("clean") {
5865
delete(rootProject.layout.buildDirectory)
5966
}
67+
68+
tasks.register("serveDokka") {
69+
dependsOn("dokkaHtml")
70+
doLast {
71+
val server = HttpServer.create(InetSocketAddress(0), 0)
72+
val root = file("core/build/dokka/html")
73+
74+
val handler =
75+
com.sun.net.httpserver.HttpHandler { exchange: HttpExchange ->
76+
val rawPath = exchange.requestURI.path
77+
val cleanPath = URLDecoder.decode(rawPath.removePrefix("/"), "UTF-8")
78+
val requestedFile = File(root, cleanPath)
79+
80+
val file =
81+
when {
82+
requestedFile.exists() && !requestedFile.isDirectory -> requestedFile
83+
else -> File(root, "index.html") // fallback
84+
}
85+
86+
val contentType =
87+
Files.probeContentType(file.toPath()) ?: "application/octet-stream"
88+
val bytes = file.readBytes()
89+
exchange.responseHeaders.add("Content-Type", contentType)
90+
exchange.sendResponseHeaders(200, bytes.size.toLong())
91+
exchange.responseBody.use { it.write(bytes) }
92+
}
93+
94+
server.createContext("/", handler)
95+
server.executor = null
96+
server.start()
97+
98+
println("📘 Serving Dokka docs at http://localhost:${server.address.port}/")
99+
println("Press Ctrl+C to stop.")
100+
101+
// Keep the task alive
102+
Thread.currentThread().join()
103+
}
104+
}

core/build.gradle.kts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ plugins {
2121
id("com.powersync.plugins.sonatype")
2222
alias(libs.plugins.mokkery)
2323
alias(libs.plugins.kotlin.atomicfu)
24+
id("org.jetbrains.dokka")
2425
}
2526

2627
val binariesFolder = project.layout.buildDirectory.dir("binaries/desktop")
@@ -315,8 +316,8 @@ android {
315316
}
316317

317318
androidComponents.onVariants {
318-
tasks.named("preBuild") {
319-
dependsOn(moveJDBCJNIFiles)
319+
tasks.named("preBuild") {
320+
dependsOn(moveJDBCJNIFiles)
320321
}
321322
}
322323

0 commit comments

Comments
 (0)