[Gradle, JS] Add callbacks on configuring producing target for JS IR

This commit is contained in:
Ilya Goncharov
2019-12-24 18:53:28 +03:00
parent e7c6653182
commit 64c2b4b076
4 changed files with 37 additions and 6 deletions
@@ -32,6 +32,8 @@ 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"
@@ -203,6 +205,14 @@ open class KotlinBrowserJsIr @Inject constructor(target: KotlinJsIrTarget) :
}
}
fun whenProducingConfigured(body: KotlinBrowserJsIr.() -> Unit) {
if (producingConfigured) {
this.body()
} else {
producingConfiguredHandlers += body
}
}
companion object {
const val PRODUCTION = "production"
const val DEVELOPMENT = "development"
@@ -36,12 +36,13 @@ abstract class KotlinJsIrSubTarget(
final override lateinit var testRuns: NamedDomainObjectContainer<KotlinJsIrPlatformTestRun>
private set
fun configure() {
protected val producingConfigured: Boolean = false
private fun configure() {
NpmResolverPlugin.apply(project)
configureBuildVariants()
configureTests()
configureMain()
target.compilations.all {
val npmProject = it.npmProject
@@ -50,6 +51,9 @@ abstract class KotlinJsIrSubTarget(
}
override fun produceKotlinLibrary() {
configure()
// configureMain()
target.compilations
.matching { it.name == KotlinCompilation.TEST_COMPILATION_NAME }
.all {
@@ -43,8 +43,11 @@ open class KotlinJsIrTarget @Inject constructor(project: Project, platformType:
private val browserLazyDelegate = lazy {
project.objects.newInstance(KotlinBrowserJsIr::class.java, this).also {
it.configure()
browserConfiguredHandlers.forEach { handler -> handler(it) }
browserConfiguredHandlers.forEach { handler ->
it.whenProducingConfigured {
handler(this)
}
}
browserConfiguredHandlers.clear()
}
}
@@ -61,8 +64,12 @@ open class KotlinJsIrTarget @Inject constructor(project: Project, platformType:
private val nodejsLazyDelegate = lazy {
project.objects.newInstance(KotlinNodeJsIr::class.java, this).also {
it.configure()
nodejsConfiguredHandlers.forEach { handler -> handler(it) }
nodejsConfiguredHandlers.forEach { handler ->
it.whenProducingConfigured {
handler(this)
}
}
nodejsConfiguredHandlers.clear()
}
}
@@ -17,6 +17,8 @@ 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 runTask(body: NodeJsExec.() -> Unit) {
@@ -40,4 +42,12 @@ open class KotlinNodeJsIr @Inject constructor(target: KotlinJsIrTarget) :
override fun configureBuildVariants() {
}
fun whenProducingConfigured(body: KotlinNodeJsIr.() -> Unit) {
if (producingConfigured) {
this.body()
} else {
producingConfiguredHandlers += body
}
}
}