Generate JS main function execution mode type
^KT-27301 In Progress
This commit is contained in:
@@ -35,6 +35,7 @@ fun generateKotlinGradleOptions(withPrinterToFile: (targetFile: File, Printer.()
|
|||||||
// specific Gradle types from internal compiler types
|
// specific Gradle types from internal compiler types
|
||||||
generateKotlinVersion(apiSrcDir, withPrinterToFile)
|
generateKotlinVersion(apiSrcDir, withPrinterToFile)
|
||||||
generateJvmTarget(apiSrcDir, withPrinterToFile)
|
generateJvmTarget(apiSrcDir, withPrinterToFile)
|
||||||
|
generateJsMainFunctionExecutionMode(apiSrcDir, withPrinterToFile)
|
||||||
|
|
||||||
// common interface
|
// common interface
|
||||||
val commonInterfaceFqName = FqName("org.jetbrains.kotlin.gradle.dsl.KotlinCommonToolOptions")
|
val commonInterfaceFqName = FqName("org.jetbrains.kotlin.gradle.dsl.KotlinCommonToolOptions")
|
||||||
|
|||||||
@@ -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("}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+15
@@ -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")
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user