[Gradle, JS] Add callbacks on configuring producing target for JS IR
This commit is contained in:
+10
@@ -32,6 +32,8 @@ open class KotlinBrowserJsIr @Inject constructor(target: KotlinJsIrTarget) :
|
|||||||
|
|
||||||
private lateinit var buildVariants: NamedDomainObjectContainer<BuildVariant>
|
private lateinit var buildVariants: NamedDomainObjectContainer<BuildVariant>
|
||||||
|
|
||||||
|
private val producingConfiguredHandlers: MutableList<KotlinBrowserJsIr.() -> Unit> = mutableListOf()
|
||||||
|
|
||||||
override val testTaskDescription: String
|
override val testTaskDescription: String
|
||||||
get() = "Run all ${target.name} tests inside browser using karma and webpack"
|
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 {
|
companion object {
|
||||||
const val PRODUCTION = "production"
|
const val PRODUCTION = "production"
|
||||||
const val DEVELOPMENT = "development"
|
const val DEVELOPMENT = "development"
|
||||||
|
|||||||
+6
-2
@@ -36,12 +36,13 @@ abstract class KotlinJsIrSubTarget(
|
|||||||
final override lateinit var testRuns: NamedDomainObjectContainer<KotlinJsIrPlatformTestRun>
|
final override lateinit var testRuns: NamedDomainObjectContainer<KotlinJsIrPlatformTestRun>
|
||||||
private set
|
private set
|
||||||
|
|
||||||
fun configure() {
|
protected val producingConfigured: Boolean = false
|
||||||
|
|
||||||
|
private fun configure() {
|
||||||
NpmResolverPlugin.apply(project)
|
NpmResolverPlugin.apply(project)
|
||||||
|
|
||||||
configureBuildVariants()
|
configureBuildVariants()
|
||||||
configureTests()
|
configureTests()
|
||||||
configureMain()
|
|
||||||
|
|
||||||
target.compilations.all {
|
target.compilations.all {
|
||||||
val npmProject = it.npmProject
|
val npmProject = it.npmProject
|
||||||
@@ -50,6 +51,9 @@ abstract class KotlinJsIrSubTarget(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun produceKotlinLibrary() {
|
override fun produceKotlinLibrary() {
|
||||||
|
configure()
|
||||||
|
// configureMain()
|
||||||
|
|
||||||
target.compilations
|
target.compilations
|
||||||
.matching { it.name == KotlinCompilation.TEST_COMPILATION_NAME }
|
.matching { it.name == KotlinCompilation.TEST_COMPILATION_NAME }
|
||||||
.all {
|
.all {
|
||||||
|
|||||||
+11
-4
@@ -43,8 +43,11 @@ open class KotlinJsIrTarget @Inject constructor(project: Project, platformType:
|
|||||||
|
|
||||||
private val browserLazyDelegate = lazy {
|
private val browserLazyDelegate = lazy {
|
||||||
project.objects.newInstance(KotlinBrowserJsIr::class.java, this).also {
|
project.objects.newInstance(KotlinBrowserJsIr::class.java, this).also {
|
||||||
it.configure()
|
browserConfiguredHandlers.forEach { handler ->
|
||||||
browserConfiguredHandlers.forEach { handler -> handler(it) }
|
it.whenProducingConfigured {
|
||||||
|
handler(this)
|
||||||
|
}
|
||||||
|
}
|
||||||
browserConfiguredHandlers.clear()
|
browserConfiguredHandlers.clear()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -61,8 +64,12 @@ open class KotlinJsIrTarget @Inject constructor(project: Project, platformType:
|
|||||||
|
|
||||||
private val nodejsLazyDelegate = lazy {
|
private val nodejsLazyDelegate = lazy {
|
||||||
project.objects.newInstance(KotlinNodeJsIr::class.java, this).also {
|
project.objects.newInstance(KotlinNodeJsIr::class.java, this).also {
|
||||||
it.configure()
|
nodejsConfiguredHandlers.forEach { handler ->
|
||||||
nodejsConfiguredHandlers.forEach { handler -> handler(it) }
|
it.whenProducingConfigured {
|
||||||
|
handler(this)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
nodejsConfiguredHandlers.clear()
|
nodejsConfiguredHandlers.clear()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+10
@@ -17,6 +17,8 @@ open class KotlinNodeJsIr @Inject constructor(target: KotlinJsIrTarget) :
|
|||||||
override val testTaskDescription: String
|
override val testTaskDescription: String
|
||||||
get() = "Run all ${target.name} tests inside nodejs using the builtin test framework"
|
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")
|
private val runTaskName = disambiguateCamelCased("run")
|
||||||
|
|
||||||
override fun runTask(body: NodeJsExec.() -> Unit) {
|
override fun runTask(body: NodeJsExec.() -> Unit) {
|
||||||
@@ -40,4 +42,12 @@ open class KotlinNodeJsIr @Inject constructor(target: KotlinJsIrTarget) :
|
|||||||
|
|
||||||
override fun configureBuildVariants() {
|
override fun configureBuildVariants() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun whenProducingConfigured(body: KotlinNodeJsIr.() -> Unit) {
|
||||||
|
if (producingConfigured) {
|
||||||
|
this.body()
|
||||||
|
} else {
|
||||||
|
producingConfiguredHandlers += body
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user