Generate Js source map embed mode type

^KT-27301 In Progress
This commit is contained in:
Yahor Berdnikau
2022-08-30 11:45:31 +02:00
parent 626bd34319
commit c1ed683ed8
3 changed files with 48 additions and 0 deletions
@@ -37,6 +37,7 @@ fun generateKotlinGradleOptions(withPrinterToFile: (targetFile: File, Printer.()
generateJvmTarget(apiSrcDir, withPrinterToFile)
generateJsMainFunctionExecutionMode(apiSrcDir, withPrinterToFile)
generateJsModuleKind(apiSrcDir, withPrinterToFile)
generateJsSourceMapEmbedMode(apiSrcDir, withPrinterToFile)
// common interface
val commonInterfaceFqName = FqName("org.jetbrains.kotlin.gradle.dsl.KotlinCommonToolOptions")
@@ -72,3 +72,34 @@ internal fun generateJsModuleKind(
}
}
}
internal fun generateJsSourceMapEmbedMode(
apiDir: File,
filePrinter: (targetFile: File, Printer.() -> Unit) -> Unit
) {
val jsSourceMapEmbedKindFqName = FqName("org.jetbrains.kotlin.gradle.dsl.JsSourceMapEmbedMode")
filePrinter(file(apiDir, jsSourceMapEmbedKindFqName)) {
generateDeclaration("enum class", jsSourceMapEmbedKindFqName, afterType = "(val mode: String)") {
val modes = hashMapOf(
K2JsArgumentConstants::SOURCE_MAP_SOURCE_CONTENT_ALWAYS.name to K2JsArgumentConstants.SOURCE_MAP_SOURCE_CONTENT_ALWAYS,
K2JsArgumentConstants::SOURCE_MAP_SOURCE_CONTENT_NEVER.name to K2JsArgumentConstants.SOURCE_MAP_SOURCE_CONTENT_NEVER,
K2JsArgumentConstants::SOURCE_MAP_SOURCE_CONTENT_INLINING.name to K2JsArgumentConstants.SOURCE_MAP_SOURCE_CONTENT_INLINING,
)
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): JsSourceMapEmbedMode =")
println(" JsSourceMapEmbedMode.values().firstOrNull { it.mode == mode }")
println(" ?: throw IllegalArgumentException(\"Unknown JS source map embed mode: ${'$'}mode\")")
}
println("}")
}
}
}
@@ -0,0 +1,16 @@
// DO NOT EDIT MANUALLY!
// Generated by org/jetbrains/kotlin/generators/arguments/GenerateGradleOptions.kt
package org.jetbrains.kotlin.gradle.dsl
@Suppress("DEPRECATION")
enum class JsSourceMapEmbedMode (val mode: String) {
SOURCE_MAP_SOURCE_CONTENT_INLINING("inlining"),
SOURCE_MAP_SOURCE_CONTENT_NEVER("never"),
SOURCE_MAP_SOURCE_CONTENT_ALWAYS("always");
companion object {
fun fromMode(mode: String): JsSourceMapEmbedMode =
JsSourceMapEmbedMode.values().firstOrNull { it.mode == mode }
?: throw IllegalArgumentException("Unknown JS source map embed mode: $mode")
}
}