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+
17plugins {
28 alias(libs.plugins.jetbrainsCompose) apply false
39 alias(libs.plugins.compose.compiler) apply false
@@ -16,6 +22,8 @@ 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 libs.versions.dokkaBase
26+ id(" dokka-convention" )
1927}
2028
2129allprojects {
@@ -54,6 +62,58 @@ subprojects {
5462 version = LIBRARY_VERSION
5563}
5664
57- tasks.register <Delete >(" clean" ) {
65+ tasks.getByName <Delete >(" clean" ) {
5866 delete(rootProject.layout.buildDirectory)
5967}
68+
69+ // Merges individual module docs into a single HTML output
70+ dependencies {
71+ dokka(project(" :core:" ))
72+ dokka(project(" :connectors:supabase" ))
73+ dokka(project(" :compose:" ))
74+ }
75+
76+ dokka {
77+ moduleName.set(" PowerSync Kotlin" )
78+ }
79+
80+ // Serve the generated Dokka documentation using a simple HTTP server
81+ // File changes are not watched here
82+ tasks.register(" serveDokka" ) {
83+ group = " dokka"
84+ dependsOn(" dokkaGenerate" )
85+ doLast {
86+ val server = HttpServer .create(InetSocketAddress (0 ), 0 )
87+ val root = file(" build/dokka/html" )
88+
89+ val handler =
90+ com.sun.net.httpserver.HttpHandler { exchange: HttpExchange ->
91+ val rawPath = exchange.requestURI.path
92+ val cleanPath = URLDecoder .decode(rawPath.removePrefix(" /" ), " UTF-8" )
93+ val requestedFile = File (root, cleanPath)
94+
95+ val file =
96+ when {
97+ requestedFile.exists() && ! requestedFile.isDirectory -> requestedFile
98+ else -> File (root, " index.html" ) // fallback
99+ }
100+
101+ val contentType =
102+ Files .probeContentType(file.toPath()) ? : " application/octet-stream"
103+ val bytes = file.readBytes()
104+ exchange.responseHeaders.add(" Content-Type" , contentType)
105+ exchange.sendResponseHeaders(200 , bytes.size.toLong())
106+ exchange.responseBody.use { it.write(bytes) }
107+ }
108+
109+ server.createContext(" /" , handler)
110+ server.executor = null
111+ server.start()
112+
113+ println (" 📘 Serving Dokka docs at http://localhost:${server.address.port} /" )
114+ println (" Press Ctrl+C to stop." )
115+
116+ // Keep the task alive
117+ Thread .currentThread().join()
118+ }
119+ }
0 commit comments