[JS, Wizard] Set js compiler per module

^KT-41418 fixed
This commit is contained in:
Ilya Goncharov
2020-08-26 14:15:51 +03:00
parent f824f03fa2
commit 13bf15b403
4 changed files with 49 additions and 23 deletions
@@ -19,12 +19,23 @@ interface TargetIR : MultiplatformIR
data class TargetAccessIR(
val type: ModuleSubType,
val nonDefaultName: String? // `null` stands for default target name
val nonDefaultName: String?, // `null` stands for default target name
val additionalParams: List<Any> = listOf()
) : TargetIR {
override fun GradlePrinter.renderGradle() {
+type.toString()
par {
nonDefaultName?.let { +it.quotified }
nonDefaultName?.let {
+it.quotified
if (additionalParams.isNotEmpty()) +", "
}
if (additionalParams.isNotEmpty()) {
additionalParams
.joinToString {
it.toString()
}
.apply { +this }
}
}
}
}
@@ -56,8 +67,18 @@ data class DefaultTargetConfigurationIR(
override fun GradlePrinter.renderGradle() {
+targetAccess.type.toString()
if (irs.isEmpty() || targetAccess.nonDefaultName != null) par {
targetAccess.nonDefaultName?.let { +it.quotified }
if (irs.isEmpty() || targetAccess.nonDefaultName != null || targetAccess.additionalParams.isNotEmpty()) par {
targetAccess.nonDefaultName?.let {
+it.quotified
if (targetAccess.additionalParams.isNotEmpty()) +", "
}
if (targetAccess.additionalParams.isNotEmpty()) {
targetAccess.additionalParams
.joinToString {
it.toString()
}
.apply { +this }
}
}
if (irs.isNotEmpty()) {
+" "; inBrackets { irs.listNl() }
@@ -44,7 +44,6 @@ interface JSConfigurator : ModuleConfiguratorWithModuleType, ModuleConfiguratorW
GradlePlugin.gradleProperties
.addValues(
"kotlin.js.generate.executable.default" to "false",
"kotlin.js.compiler" to settingsValue(module, compiler).text.toLowerCase()
)
override fun getConfiguratorSettings(): List<ModuleConfiguratorSetting<*, *>> =
@@ -139,9 +138,6 @@ abstract class JsSinglePlatformModuleConfigurator :
super<ModuleConfiguratorWithTests>.getConfiguratorSettings() +
super<JSConfigurator>.getConfiguratorSettings()
@NonNls
override val suggestedModuleName = "js"
override fun defaultTestFramework(): KotlinTestFramework = KotlinTestFramework.JS
override val canContainSubModules = false
@@ -158,7 +154,7 @@ abstract class JsSinglePlatformModuleConfigurator :
module: Module
): List<BuildSystemIR> = irsList {
"kotlin" {
"js" {
"js(${reader.settingsValue(module, JSConfigurator.compiler).text})" {
subTarget(module, reader)
}
}
@@ -171,6 +167,9 @@ object BrowserJsSinglePlatformModuleConfigurator : JsSinglePlatformModuleConfigu
@NonNls
override val id = "jsBrowserSinglePlatform"
@NonNls
override val suggestedModuleName = "browser"
override val moduleKind = ModuleKind.singleplatformJsBrowser
override fun getConfiguratorSettings(): List<ModuleConfiguratorSetting<*, *>> {
@@ -189,6 +188,9 @@ object NodeJsSinglePlatformModuleConfigurator : JsSinglePlatformModuleConfigurat
@NonNls
override val id = "jsNodeSinglePlatform"
@NonNls
override val suggestedModuleName = "nodejs"
override val moduleKind = ModuleKind.singleplatformJsNode
override fun GradleIRListBuilder.subTarget(module: Module, reader: Reader) {
@@ -65,10 +65,14 @@ interface SimpleTargetConfigurator : TargetConfigurator {
}
}
internal fun Module.createTargetAccessIr(moduleSubType: ModuleSubType) =
internal fun Module.createTargetAccessIr(
moduleSubType: ModuleSubType,
additionalParams: List<Any?> = listOf()
) =
TargetAccessIR(
moduleSubType,
name.takeIf { it != moduleSubType.name }
name.takeIf { it != moduleSubType.name },
additionalParams.filterNotNull()
)
@@ -94,9 +98,6 @@ object JsBrowserTargetConfigurator : JsTargetConfigurator, ModuleConfiguratorWit
@NonNls
override val id = "jsBrowser"
@NonNls
override val suggestedModuleName = "browser"
override val text = KotlinNewProjectWizardBundle.message("module.configurator.js.browser")
override fun defaultTestFramework(): KotlinTestFramework = KotlinTestFramework.JS
@@ -105,7 +106,10 @@ object JsBrowserTargetConfigurator : JsTargetConfigurator, ModuleConfiguratorWit
module: Module
): List<BuildSystemIR> = irsList {
+DefaultTargetConfigurationIR(
module.createTargetAccessIr(ModuleSubType.js)
module.createTargetAccessIr(
ModuleSubType.js,
listOf(settingValue(module, JSConfigurator.compiler)?.text)
)
) {
browserSubTarget(module, this@createTargetIrs)
}
@@ -116,17 +120,16 @@ object JsNodeTargetConfigurator : JsTargetConfigurator {
@NonNls
override val id = "jsNode"
@NonNls
override val suggestedModuleName = "nodeJs"
override val text = KotlinNewProjectWizardBundle.message("module.configurator.js.node")
override fun Reader.createTargetIrs(
module: Module
): List<BuildSystemIR> = irsList {
+DefaultTargetConfigurationIR(
module.createTargetAccessIr(ModuleSubType.js)
module.createTargetAccessIr(
ModuleSubType.js,
listOf(settingValue(module, JSConfigurator.compiler)?.text)
)
) {
nodejsSubTarget(module, this@createTargetIrs)
}
@@ -287,7 +287,7 @@ object FrontendApplicationProjectTemplate : ProjectTemplate() {
get() = listOf(
KotlinPlugin.modules.reference withValue listOf(
Module(
"js",
"browser",
BrowserJsSinglePlatformModuleConfigurator,
template = SimpleJsClientTemplate(),
sourcesets = SourcesetType.ALL.map { type ->
@@ -312,7 +312,7 @@ object ReactApplicationProjectTemplate : ProjectTemplate() {
get() = listOf(
KotlinPlugin.modules.reference withValue listOf(
Module(
"js",
"react",
BrowserJsSinglePlatformModuleConfigurator,
template = ReactJsClientTemplate(),
sourcesets = SourcesetType.ALL.map { type ->
@@ -431,7 +431,7 @@ object NodeJsApplicationProjectTemplate : ProjectTemplate() {
get() = listOf(
KotlinPlugin.modules.reference withValue listOf(
Module(
"js",
"nodejs",
NodeJsSinglePlatformModuleConfigurator,
template = SimpleNodeJsTemplate(),
sourcesets = SourcesetType.ALL.map { type ->