[Gradle, JS] NodeJs and browser producing handlers

This commit is contained in:
Ilya Goncharov
2019-12-24 20:08:45 +03:00
parent 2de7051165
commit f936a0fc9b
3 changed files with 20 additions and 7 deletions
@@ -32,11 +32,16 @@ open class KotlinBrowserJsIr @Inject constructor(target: KotlinJsIrTarget) :
private lateinit var buildVariants: NamedDomainObjectContainer<BuildVariant>
private val producingConfiguredHandlers: MutableList<KotlinBrowserJsIr.() -> Unit> = mutableListOf()
override val testTaskDescription: String
get() = "Run all ${target.name} tests inside browser using karma and webpack"
override fun configure() {
super.configure()
browserProducingConfiguredHandlers.forEach { handler ->
handler(this)
}
}
override fun configureDefaultTestFramework(it: KotlinJsTest) {
it.useKarma {
useChromeHeadless()
@@ -209,7 +214,7 @@ open class KotlinBrowserJsIr @Inject constructor(target: KotlinJsIrTarget) :
if (producingConfigured) {
this.body()
} else {
producingConfiguredHandlers += body
browserProducingConfiguredHandlers += body
}
}
@@ -38,7 +38,10 @@ abstract class KotlinJsIrSubTarget(
protected val producingConfigured: Boolean = false
private fun configure() {
protected val browserProducingConfiguredHandlers: MutableList<KotlinBrowserJsIr.() -> Unit> = mutableListOf()
protected val nodejsProducingConfiguredHandlers: MutableList<KotlinNodeJsIr.() -> Unit> = mutableListOf()
protected open fun configure() {
NpmResolverPlugin.apply(project)
configureBuildVariants()
@@ -17,10 +17,15 @@ open class KotlinNodeJsIr @Inject constructor(target: KotlinJsIrTarget) :
override val testTaskDescription: String
get() = "Run all ${target.name} tests inside nodejs using the builtin test framework"
private val producingConfiguredHandlers: MutableList<KotlinNodeJsIr.() -> Unit> = mutableListOf()
private val runTaskName = disambiguateCamelCased("run")
override fun configure() {
super.configure()
nodejsProducingConfiguredHandlers.forEach { handler ->
handler(this)
}
}
override fun runTask(body: NodeJsExec.() -> Unit) {
(project.tasks.getByName(runTaskName) as NodeJsExec).body()
}
@@ -47,7 +52,7 @@ open class KotlinNodeJsIr @Inject constructor(target: KotlinJsIrTarget) :
if (producingConfigured) {
this.body()
} else {
producingConfiguredHandlers += body
nodejsProducingConfiguredHandlers += body
}
}
}