-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle.kts
155 lines (128 loc) · 4.85 KB
/
build.gradle.kts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
val rootGroupId = "com.theagilemonkeys.ellmental"
val kotlinVersion: String by project
val kotlinxSerializationVersion: String by project
val kotestVersion: String by project
val arrowVersion: String by project
val arrowMetaVersion: String by project
val kotlinOpenaiVersion: String by project
val dotenvKotlinVersion: String by project
plugins {
kotlin("jvm") version "1.8.22"
id("com.google.devtools.ksp") version "1.8.22-1.0.11"
id("maven-publish")
id("org.jetbrains.dokka") version "1.8.20"
}
repositories {
mavenCentral()
}
subprojects {
group = rootGroupId
version = rootProject.version.toString()
apply(plugin = "kotlin")
apply(plugin = "com.google.devtools.ksp")
apply(plugin = "maven-publish")
apply(plugin = "org.jetbrains.dokka")
repositories {
mavenCentral()
}
configure<PublishingExtension> {
publications {
create<MavenPublication>("mavenJava") {
from(components["java"])
}
}
}
tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "17"
kotlinOptions.freeCompilerArgs = listOf("-Xcontext-receivers")
}
dependencies {
"ksp"("io.arrow-kt:arrow-optics-ksp-plugin:$arrowVersion")
"implementation"(kotlin("stdlib"))
"implementation"(kotlin("reflect"))
"implementation"("io.github.cdimascio:dotenv-kotlin:$dotenvKotlinVersion")
"implementation"("com.aallam.openai:openai-client:$kotlinOpenaiVersion")
"implementation"("org.jetbrains.kotlinx:kotlinx-serialization-core:$kotlinxSerializationVersion")
"implementation"("org.jetbrains.kotlinx:kotlinx-serialization-json:$kotlinxSerializationVersion")
"implementation"("io.arrow-kt:arrow-core:$arrowVersion")
"implementation"("io.arrow-kt:arrow-fx-coroutines:$arrowVersion")
"implementation"("io.arrow-kt:arrow-optics:$arrowVersion")
"testImplementation"("org.jetbrains.kotlin:kotlin-test-junit:$kotlinVersion")
"testImplementation"("io.kotest:kotest-runner-junit5:$kotestVersion")
"testImplementation"("io.kotest:kotest-assertions-core:$kotestVersion")
"testImplementation"("io.kotest:kotest-property:$kotestVersion")
}
tasks.withType<Test>().configureEach {
useJUnitPlatform()
}
}
tasks.register<DefaultTask>("processDokkaDocs") {
dependsOn("dokkaGfmCollector")
doLast {
val sourceDir = file("build/dokka/gfmCollector")
val targetDir = file("website/docs/api_docs")
fun String.convertDashedToUpper(): String {
var shouldCapitalize = false
return this.map {
when {
it == '-' -> {
shouldCapitalize = true
""
}
shouldCapitalize -> {
shouldCapitalize = false
it.toUpperCase()
}
else -> it
}
}.joinToString("")
}
delete(targetDir)
copy {
from(sourceDir)
into(targetDir)
}
fileTree(targetDir).forEach { file ->
if (file.isFile) {
val simpleParentName = file.parentFile.name.convertDashedToUpper()
val parentName = file.parentFile.name.replace(rootGroupId, "").convertDashedToUpper()
val fileName = file.nameWithoutExtension.convertDashedToUpper()
val content = file
.readText()
.replace("<br>", "<br/>")
.replace("[jvm]\\", "")
.replace("${file.parentFile.name}.md", "index.md")
val tag = when {
content.contains("Package") -> ""
content.contains("interface") -> "interface"
content.contains("constructor") -> "class"
content.contains("object [Companion]") -> "companion"
content.contains("fun ") -> "fun"
content.contains("val ") -> "val"
else -> ""
}
if (simpleParentName == fileName) {
file.delete()
return@forEach
}
val fileLabel = when (fileName) {
parentName -> parentName
"index" -> parentName
else -> fileName
}
val label = if (tag == "companion") "object" else fileLabel
val contentWithFrontMatter = """---
title: $label
sidebar_label: "$tag $label"
sidebar_class_name: "codetag-sidebar"
sidebar_custom_props:
tag: $tag
name: $label
---
$content""".trimIndent()
file.writeText(contentWithFrontMatter)
}
}
}
}