From 9cde4927ce489d7274b087a881927da2efd1fbed Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 5 Dec 2024 21:04:54 +0600 Subject: [PATCH] refactor and fixes --- tgbotapi.webapps/.templates/generator.kts | 4 ++-- .../EventType{{$event_name_uppercase}}.kt | 0 .../WebApp{{$event_name_uppercase}}.kt | 0 .../{{$event_name_uppercase}}.kt | 0 .../tgbotapi/webapps/events/events_generator.main.kts | 8 ++++---- 5 files changed, 6 insertions(+), 6 deletions(-) rename tgbotapi.webapps/.templates/{events => {{$subpackage}}}/EventType{{$event_name_uppercase}}.kt (100%) rename tgbotapi.webapps/.templates/{events => {{$subpackage}}}/WebApp{{$event_name_uppercase}}.kt (100%) rename tgbotapi.webapps/.templates/{events => {{$subpackage}}}/{{$event_name_uppercase}}.kt (100%) diff --git a/tgbotapi.webapps/.templates/generator.kts b/tgbotapi.webapps/.templates/generator.kts index 7b88a95d6b..5fc31d86a1 100755 --- a/tgbotapi.webapps/.templates/generator.kts +++ b/tgbotapi.webapps/.templates/generator.kts @@ -35,7 +35,7 @@ val templatesFolders = mutableListOf() var extensions: List? = null var skipPrompts: Boolean = false val commandLineArgs = mutableMapOf() -val globalEnvs = System.getenv() +val globalEnvs = System.getenv().toMutableMap() fun String.replaceWithVariables(envs: Map): String { var currentString = this @@ -183,7 +183,7 @@ fun readParameters() { readParameters() -val envs: MutableMap = envFile ?.let { readEnvs(it.readText(), null) } ?.toMutableMap() ?: mutableMapOf() +val envs: MutableMap = (envFile ?.let { readEnvs(it.readText(), null) } ?: (globalEnvs + commandLineArgs)).toMutableMap() println( """ diff --git a/tgbotapi.webapps/.templates/events/EventType{{$event_name_uppercase}}.kt b/tgbotapi.webapps/.templates/{{$subpackage}}/EventType{{$event_name_uppercase}}.kt similarity index 100% rename from tgbotapi.webapps/.templates/events/EventType{{$event_name_uppercase}}.kt rename to tgbotapi.webapps/.templates/{{$subpackage}}/EventType{{$event_name_uppercase}}.kt diff --git a/tgbotapi.webapps/.templates/events/WebApp{{$event_name_uppercase}}.kt b/tgbotapi.webapps/.templates/{{$subpackage}}/WebApp{{$event_name_uppercase}}.kt similarity index 100% rename from tgbotapi.webapps/.templates/events/WebApp{{$event_name_uppercase}}.kt rename to tgbotapi.webapps/.templates/{{$subpackage}}/WebApp{{$event_name_uppercase}}.kt diff --git a/tgbotapi.webapps/.templates/events/{{$event_name_uppercase}}.kt b/tgbotapi.webapps/.templates/{{$subpackage}}/{{$event_name_uppercase}}.kt similarity index 100% rename from tgbotapi.webapps/.templates/events/{{$event_name_uppercase}}.kt rename to tgbotapi.webapps/.templates/{{$subpackage}}/{{$event_name_uppercase}}.kt diff --git a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/events/events_generator.main.kts b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/events/events_generator.main.kts index b10c079ecf..aa03ac628a 100755 --- a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/events/events_generator.main.kts +++ b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/events/events_generator.main.kts @@ -10,9 +10,11 @@ val rfAbsolutePath = rootFolder.absolutePath fun generateEvent(eventName: String, callbacks: String) { val uppercaseEventName = eventName.take(1).uppercase() + eventName.drop(1) - val command = "${rfAbsolutePath}/.templates/generator.kts -s -a \"event_name=$eventName\" -a \"event_name_uppercase=$uppercaseEventName\" -a \"callback_args=$callbacks\" --env \"${rfAbsolutePath}/.templates/events/.env\" -o \"./\" -ex \"kt\" \"${rfAbsolutePath}/.templates/events/\"" + val subpackage = eventName.map { if (it.isUpperCase()) "_${it.lowercase()}" else it }.joinToString("") + val command = "${rfAbsolutePath}/.templates/generator.kts -s -a \"subpackage=$subpackage\" -a \"event_name=$eventName\" -a \"event_name_uppercase=$uppercaseEventName\" -a \"callback_args=$callbacks\" -o \"./\" -ex \"kt\" \"${rfAbsolutePath}/.templates/{{\$subpackage}}\"" - Runtime.getRuntime().exec(command).waitFor() + println(command) + println(Runtime.getRuntime().exec(command).waitFor()) } val eventsList: JsonArray = Json.parseToJsonElement(File("EventsList.json").readText()).jsonArray @@ -23,5 +25,3 @@ eventsList.forEach { it.jsonObject["callback"] ?.jsonPrimitive ?.content ?: "" ) } - -println(eventsList.toString())