From 521e5942d1f0ad6417fbdd41b3dbafd912dada21 Mon Sep 17 00:00:00 2001 From: Abe Pazos Date: Sat, 14 Dec 2024 16:17:04 +0100 Subject: [PATCH] Add a Gradle task to generate appList.kt --- build.gradle.kts | 41 +++++++++++++++++++++--- src/commonMain/kotlin/TemplateProgram.kt | 7 ---- src/commonMain/kotlin/appList.kt | 6 ++++ 3 files changed, 42 insertions(+), 12 deletions(-) create mode 100644 src/commonMain/kotlin/appList.kt diff --git a/build.gradle.kts b/build.gradle.kts index 183659e..8540d5d 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -20,7 +20,7 @@ val orxFeatures = setOf( // "orx-parameters", // "orx-shade-styles", // "orx-shader-phrases", - "orx-shapes", + "orx-shapes", // "orx-quadtree", ) @@ -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) } @@ -92,4 +90,37 @@ val embedSourcesTask by tasks.creating(Task::class) { } tasks.named("jsRun") { dependsOn(embedSourcesTask) } -tasks.named("jsBrowserProductionWebpack") { dependsOn(embedSourcesTask)} \ No newline at end of file +tasks.named("jsBrowserProductionWebpack") { dependsOn(embedSourcesTask) } + + +task("update appList") { + group = " \uD83E\uDD8C OPENRNDR" + + doLast { + val rows = mutableListOf() + 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.") + } +} \ No newline at end of file diff --git a/src/commonMain/kotlin/TemplateProgram.kt b/src/commonMain/kotlin/TemplateProgram.kt index 5ea2291..c33ca93 100644 --- a/src/commonMain/kotlin/TemplateProgram.kt +++ b/src/commonMain/kotlin/TemplateProgram.kt @@ -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() diff --git a/src/commonMain/kotlin/appList.kt b/src/commonMain/kotlin/appList.kt new file mode 100644 index 0000000..1630b60 --- /dev/null +++ b/src/commonMain/kotlin/appList.kt @@ -0,0 +1,6 @@ +// This file was auto-generated by Gradle +val myApps = mapOf( + "fabulousPink" to :: fabulousPink, + "bouncyBubbles" to :: bouncyBubbles, + "justGreen" to :: justGreen, +)