Generate JS module kind type
^KT-27301 In Progress
This commit is contained in:
@@ -36,6 +36,7 @@ fun generateKotlinGradleOptions(withPrinterToFile: (targetFile: File, Printer.()
|
|||||||
generateKotlinVersion(apiSrcDir, withPrinterToFile)
|
generateKotlinVersion(apiSrcDir, withPrinterToFile)
|
||||||
generateJvmTarget(apiSrcDir, withPrinterToFile)
|
generateJvmTarget(apiSrcDir, withPrinterToFile)
|
||||||
generateJsMainFunctionExecutionMode(apiSrcDir, withPrinterToFile)
|
generateJsMainFunctionExecutionMode(apiSrcDir, withPrinterToFile)
|
||||||
|
generateJsModuleKind(apiSrcDir, withPrinterToFile)
|
||||||
|
|
||||||
// common interface
|
// common interface
|
||||||
val commonInterfaceFqName = FqName("org.jetbrains.kotlin.gradle.dsl.KotlinCommonToolOptions")
|
val commonInterfaceFqName = FqName("org.jetbrains.kotlin.gradle.dsl.KotlinCommonToolOptions")
|
||||||
|
|||||||
@@ -39,3 +39,36 @@ internal fun generateJsMainFunctionExecutionMode(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal fun generateJsModuleKind(
|
||||||
|
apiDir: File,
|
||||||
|
filePrinter: (targetFile: File, Printer.() -> Unit) -> Unit
|
||||||
|
) {
|
||||||
|
val jsModuleKindFqName = FqName("org.jetbrains.kotlin.gradle.dsl.JsModuleKind")
|
||||||
|
filePrinter(file(apiDir, jsModuleKindFqName)) {
|
||||||
|
generateDeclaration("enum class", jsModuleKindFqName, afterType = "(val kind: String)") {
|
||||||
|
val kinds = hashMapOf(
|
||||||
|
K2JsArgumentConstants::MODULE_PLAIN.name to K2JsArgumentConstants.MODULE_PLAIN,
|
||||||
|
K2JsArgumentConstants::MODULE_AMD.name to K2JsArgumentConstants.MODULE_AMD,
|
||||||
|
K2JsArgumentConstants::MODULE_COMMONJS.name to K2JsArgumentConstants.MODULE_COMMONJS,
|
||||||
|
K2JsArgumentConstants::MODULE_UMD.name to K2JsArgumentConstants.MODULE_UMD,
|
||||||
|
K2JsArgumentConstants::MODULE_ES.name to K2JsArgumentConstants.MODULE_ES
|
||||||
|
)
|
||||||
|
|
||||||
|
val lastIndex = kinds.size - 1
|
||||||
|
kinds.entries.forEachIndexed { index, mode ->
|
||||||
|
val lastChar = if (index == lastIndex) ";" else ","
|
||||||
|
println("${mode.key}(\"${mode.value}\")$lastChar")
|
||||||
|
}
|
||||||
|
|
||||||
|
println()
|
||||||
|
println("companion object {")
|
||||||
|
withIndent {
|
||||||
|
println("fun fromKind(kind: String): JsModuleKind =")
|
||||||
|
println(" JsModuleKind.values().firstOrNull { it.kind == kind }")
|
||||||
|
println(" ?: throw IllegalArgumentException(\"Unknown JS module kind: ${'$'}kind\")")
|
||||||
|
}
|
||||||
|
println("}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
+18
@@ -0,0 +1,18 @@
|
|||||||
|
// DO NOT EDIT MANUALLY!
|
||||||
|
// Generated by org/jetbrains/kotlin/generators/arguments/GenerateGradleOptions.kt
|
||||||
|
package org.jetbrains.kotlin.gradle.dsl
|
||||||
|
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
|
enum class JsModuleKind (val kind: String) {
|
||||||
|
MODULE_AMD("amd"),
|
||||||
|
MODULE_PLAIN("plain"),
|
||||||
|
MODULE_ES("es"),
|
||||||
|
MODULE_COMMONJS("commonjs"),
|
||||||
|
MODULE_UMD("umd");
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
fun fromKind(kind: String): JsModuleKind =
|
||||||
|
JsModuleKind.values().firstOrNull { it.kind == kind }
|
||||||
|
?: throw IllegalArgumentException("Unknown JS module kind: $kind")
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user