Skip to content

Commit

Permalink
Add a Gradle task to generate appList.kt
Browse files Browse the repository at this point in the history
  • Loading branch information
hamoid committed Dec 14, 2024
1 parent 357c9e5 commit 521e594
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 12 deletions.
41 changes: 36 additions & 5 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ val orxFeatures = setOf<String>(
// "orx-parameters",
// "orx-shade-styles",
// "orx-shader-phrases",
"orx-shapes",
"orx-shapes",
// "orx-quadtree",
)

Expand Down Expand Up @@ -68,9 +68,7 @@ tasks {

val nonStableKeywords = listOf("alpha", "beta", "rc")

fun isNonStable(
version: String
) = nonStableKeywords.any {
fun isNonStable(version: String) = nonStableKeywords.any {
version.lowercase().contains(it)
}

Expand All @@ -92,4 +90,37 @@ val embedSourcesTask by tasks.creating(Task::class) {
}

tasks.named("jsRun") { dependsOn(embedSourcesTask) }
tasks.named("jsBrowserProductionWebpack") { dependsOn(embedSourcesTask)}
tasks.named("jsBrowserProductionWebpack") { dependsOn(embedSourcesTask) }


task("update appList") {
group = " \uD83E\uDD8C OPENRNDR"

doLast {
val rows = mutableListOf<String>()
val regex = """\bfun\s+(\w+)\(\)\s+=\s+application\s+\{""".toRegex()

File("${layout.projectDirectory}/src/commonMain/kotlin/").walkTopDown().filter {
it.name.endsWith(".kt")
}.map { it.absolutePath }.forEach { fileName ->
File(fileName).readLines().filter { line ->
line.contains(" application ")
}.forEach { appLine ->
regex.find(appLine)?.let {
val functionName = it.groupValues[1]
rows.add(""" "$functionName" to :: $functionName,""")
}
}
}

val outputFile = File("${layout.projectDirectory}/src/commonMain/kotlin/appList.kt")
outputFile.writeText(
"// This file was auto-generated by Gradle\n" +
"val myApps = mapOf(\n" +
rows.joinToString("\n") +
"\n)\n"
)

println("${outputFile.absolutePath} updated.")
}
}
7 changes: 0 additions & 7 deletions src/commonMain/kotlin/TemplateProgram.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@ import kotlinx.browser.document
import kotlinx.browser.window
import org.w3c.dom.url.URLSearchParams

// Add your application functions here
val myApps = mapOf(
"bouncyBubbles" to ::bouncyBubbles,
"justGreen" to ::justGreen,
"fabulousPink" to ::fabulousPink,
)

fun main() {
// Take the GET argument from the URL specifying which program to run. If missing take the first.
val currentProgram = URLSearchParams(window.location.search).get("program") ?: myApps.keys.first()
Expand Down
6 changes: 6 additions & 0 deletions src/commonMain/kotlin/appList.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// This file was auto-generated by Gradle
val myApps = mapOf(
"fabulousPink" to :: fabulousPink,
"bouncyBubbles" to :: bouncyBubbles,
"justGreen" to :: justGreen,
)

0 comments on commit 521e594

Please sign in to comment.