diff --git a/generators/tests/org/jetbrains/kotlin/generators/arguments/GenerateGradleOptions.kt b/generators/tests/org/jetbrains/kotlin/generators/arguments/GenerateGradleOptions.kt index e2773e0c2bf..b06cb9eebb8 100644 --- a/generators/tests/org/jetbrains/kotlin/generators/arguments/GenerateGradleOptions.kt +++ b/generators/tests/org/jetbrains/kotlin/generators/arguments/GenerateGradleOptions.kt @@ -35,6 +35,7 @@ fun generateKotlinGradleOptions(withPrinterToFile: (targetFile: File, Printer.() // specific Gradle types from internal compiler types generateKotlinVersion(apiSrcDir, withPrinterToFile) generateJvmTarget(apiSrcDir, withPrinterToFile) + generateJsMainFunctionExecutionMode(apiSrcDir, withPrinterToFile) // common interface val commonInterfaceFqName = FqName("org.jetbrains.kotlin.gradle.dsl.KotlinCommonToolOptions") @@ -368,4 +369,4 @@ object DeprecatedOptionAnnotator { val arguments = listOfNotNull(message, level).joinToString() return "@Deprecated($arguments)" } -} \ No newline at end of file +} diff --git a/generators/tests/org/jetbrains/kotlin/generators/arguments/jsTypesGenerators.kt b/generators/tests/org/jetbrains/kotlin/generators/arguments/jsTypesGenerators.kt new file mode 100644 index 00000000000..712890a9839 --- /dev/null +++ b/generators/tests/org/jetbrains/kotlin/generators/arguments/jsTypesGenerators.kt @@ -0,0 +1,41 @@ +/* + * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.generators.arguments + +import org.jetbrains.kotlin.cli.common.arguments.K2JsArgumentConstants +import org.jetbrains.kotlin.name.FqName +import org.jetbrains.kotlin.utils.Printer +import java.io.File + +internal fun generateJsMainFunctionExecutionMode( + apiDir: File, + filePrinter: (targetFile: File, Printer.() -> Unit) -> Unit +) { + val modeFqName = FqName("org.jetbrains.kotlin.gradle.dsl.JsMainFunctionExecutionMode") + filePrinter(file(apiDir, modeFqName)) { + generateDeclaration("enum class", modeFqName, afterType = "(val mode: String)") { + val modes = hashMapOf( + K2JsArgumentConstants::CALL.name to K2JsArgumentConstants.CALL, + K2JsArgumentConstants::NO_CALL.name to K2JsArgumentConstants.NO_CALL + ) + + val lastIndex = modes.size - 1 + modes.entries.forEachIndexed { index, mode -> + val lastChar = if (index == lastIndex) ";" else "," + println("${mode.key}(\"${mode.value}\")$lastChar") + } + + println() + println("companion object {") + withIndent { + println("fun fromMode(mode: String): JsMainFunctionExecutionMode =") + println(" JsMainFunctionExecutionMode.values().firstOrNull { it.mode == mode }") + println(" ?: throw IllegalArgumentException(\"Unknown main function execution mode: ${'$'}mode\")") + } + println("}") + } + } +} diff --git a/libraries/tools/kotlin-gradle-plugin-api/src/common/kotlin/org/jetbrains/kotlin/gradle/dsl/JsMainFunctionExecutionMode.kt b/libraries/tools/kotlin-gradle-plugin-api/src/common/kotlin/org/jetbrains/kotlin/gradle/dsl/JsMainFunctionExecutionMode.kt new file mode 100644 index 00000000000..e1c0d0a2b81 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-api/src/common/kotlin/org/jetbrains/kotlin/gradle/dsl/JsMainFunctionExecutionMode.kt @@ -0,0 +1,15 @@ +// DO NOT EDIT MANUALLY! +// Generated by org/jetbrains/kotlin/generators/arguments/GenerateGradleOptions.kt +package org.jetbrains.kotlin.gradle.dsl + +@Suppress("DEPRECATION") +enum class JsMainFunctionExecutionMode (val mode: String) { + CALL("call"), + NO_CALL("noCall"); + + companion object { + fun fromMode(mode: String): JsMainFunctionExecutionMode = + JsMainFunctionExecutionMode.values().firstOrNull { it.mode == mode } + ?: throw IllegalArgumentException("Unknown main function execution mode: $mode") + } +}