[Gradle, JS] Configure build and run in one place: configureMain
This commit is contained in:
+17
-19
@@ -34,9 +34,8 @@ open class KotlinBrowserJs @Inject constructor(target: KotlinJsTarget) :
|
||||
|
||||
private val dceConfigurations: MutableList<KotlinJsDce.() -> Unit> = mutableListOf()
|
||||
private val dceWebpackEntryAppliers: MutableList<KotlinJsDce.(File) -> Unit> = mutableListOf()
|
||||
private lateinit var dceTaskProvider: TaskProvider<KotlinJsDceTask>
|
||||
|
||||
lateinit var buildVariants: NamedDomainObjectContainer<BuildVariant>
|
||||
private lateinit var buildVariants: NamedDomainObjectContainer<BuildVariant>
|
||||
|
||||
override val testTaskDescription: String
|
||||
get() = "Run all ${target.name} tests inside browser using karma and webpack"
|
||||
@@ -61,17 +60,21 @@ open class KotlinBrowserJs @Inject constructor(target: KotlinJsTarget) :
|
||||
dceConfigurations.add(body)
|
||||
}
|
||||
|
||||
override fun configureRun(compilation: KotlinJsCompilation) {
|
||||
override fun configureMain(compilation: KotlinJsCompilation) {
|
||||
val dceTaskProvider = configureDce(compilation)
|
||||
|
||||
configureRun(compilation, dceTaskProvider)
|
||||
configureBuild(compilation, dceTaskProvider)
|
||||
}
|
||||
|
||||
override fun configureRun(
|
||||
compilation: KotlinJsCompilation,
|
||||
dceTaskProvider: TaskProvider<KotlinJsDceTask>?
|
||||
) {
|
||||
|
||||
val project = compilation.target.project
|
||||
val nodeJs = NodeJsRootPlugin.apply(project.rootProject)
|
||||
|
||||
val dceTaskProvider = if (::dceTaskProvider.isInitialized) {
|
||||
this.dceTaskProvider
|
||||
} else {
|
||||
configureDce(compilation)
|
||||
}
|
||||
|
||||
buildVariants.all { buildVariant ->
|
||||
val kind = buildVariant.kind
|
||||
val runTask = project.registerTask<KotlinWebpack>(
|
||||
@@ -121,16 +124,13 @@ open class KotlinBrowserJs @Inject constructor(target: KotlinJsTarget) :
|
||||
}
|
||||
}
|
||||
|
||||
override fun configureBuild(compilation: KotlinJsCompilation) {
|
||||
override fun configureBuild(
|
||||
compilation: KotlinJsCompilation,
|
||||
dceTaskProvider: TaskProvider<KotlinJsDceTask>?
|
||||
) {
|
||||
val project = compilation.target.project
|
||||
val nodeJs = NodeJsRootPlugin.apply(project.rootProject)
|
||||
|
||||
val dceTaskProvider = if (::dceTaskProvider.isInitialized) {
|
||||
this.dceTaskProvider
|
||||
} else {
|
||||
configureDce(compilation)
|
||||
}
|
||||
|
||||
buildVariants.all { buildVariant ->
|
||||
val kind = buildVariant.kind
|
||||
val webpackTask = project.registerTask<KotlinWebpack>(
|
||||
@@ -183,7 +183,7 @@ open class KotlinBrowserJs @Inject constructor(target: KotlinJsTarget) :
|
||||
|
||||
val kotlinTask = compilation.compileKotlinTask
|
||||
|
||||
return project.registerTask<KotlinJsDceTask>(dceTaskName) {
|
||||
return project.registerTask(dceTaskName) {
|
||||
dceConfigurations.forEach { configuration ->
|
||||
it.configuration()
|
||||
}
|
||||
@@ -201,8 +201,6 @@ open class KotlinBrowserJs @Inject constructor(target: KotlinJsTarget) :
|
||||
}
|
||||
|
||||
it.source(kotlinTask.outputFile)
|
||||
}.also {
|
||||
dceTaskProvider = it
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+15
-8
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.gradle.targets.js.subtargets
|
||||
|
||||
import org.gradle.api.NamedDomainObjectContainer
|
||||
import org.gradle.api.plugins.ExtensionAware
|
||||
import org.gradle.api.tasks.TaskProvider
|
||||
import org.gradle.language.base.plugins.LifecycleBasePlugin
|
||||
import org.jetbrains.kotlin.gradle.plugin.AbstractKotlinTargetConfigurator
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation
|
||||
@@ -20,6 +21,7 @@ import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin
|
||||
import org.jetbrains.kotlin.gradle.targets.js.npm.NpmResolverPlugin
|
||||
import org.jetbrains.kotlin.gradle.targets.js.npm.npmProject
|
||||
import org.jetbrains.kotlin.gradle.targets.js.testing.KotlinJsTest
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinJsDce
|
||||
import org.jetbrains.kotlin.gradle.tasks.registerTask
|
||||
import org.jetbrains.kotlin.gradle.testing.internal.configureConventions
|
||||
import org.jetbrains.kotlin.gradle.testing.internal.kotlinTestRegistry
|
||||
@@ -45,10 +47,7 @@ abstract class KotlinJsSubTarget(
|
||||
|
||||
configureBuildVariants()
|
||||
configureTests()
|
||||
configure {
|
||||
configureRun(it)
|
||||
configureBuild(it)
|
||||
}
|
||||
configureMain()
|
||||
|
||||
target.compilations.all {
|
||||
val npmProject = it.npmProject
|
||||
@@ -128,15 +127,23 @@ abstract class KotlinJsSubTarget(
|
||||
|
||||
protected abstract fun configureDefaultTestFramework(it: KotlinJsTest)
|
||||
|
||||
fun configure(configurator: (KotlinJsCompilation) -> Unit) {
|
||||
private fun configureMain() {
|
||||
target.compilations.all { compilation ->
|
||||
if (compilation.name == KotlinCompilation.MAIN_COMPILATION_NAME) {
|
||||
configurator(compilation)
|
||||
configureMain(compilation)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract fun configureRun(compilation: KotlinJsCompilation)
|
||||
protected abstract fun configureMain(compilation: KotlinJsCompilation)
|
||||
|
||||
protected abstract fun configureBuild(compilation: KotlinJsCompilation)
|
||||
protected abstract fun configureRun(
|
||||
compilation: KotlinJsCompilation,
|
||||
dceTaskProvider: TaskProvider<KotlinJsDce>?
|
||||
)
|
||||
|
||||
protected abstract fun configureBuild(
|
||||
compilation: KotlinJsCompilation,
|
||||
dceTaskProvider: TaskProvider<KotlinJsDce>?
|
||||
)
|
||||
}
|
||||
+15
-2
@@ -5,11 +5,13 @@
|
||||
|
||||
package org.jetbrains.kotlin.gradle.targets.js.subtargets
|
||||
|
||||
import org.gradle.api.tasks.TaskProvider
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJsCompilation
|
||||
import org.jetbrains.kotlin.gradle.targets.js.KotlinJsTarget
|
||||
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsNodeDsl
|
||||
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsExec
|
||||
import org.jetbrains.kotlin.gradle.targets.js.testing.KotlinJsTest
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinJsDce
|
||||
import javax.inject.Inject
|
||||
|
||||
open class KotlinNodeJs @Inject constructor(target: KotlinJsTarget) :
|
||||
@@ -26,12 +28,23 @@ open class KotlinNodeJs @Inject constructor(target: KotlinJsTarget) :
|
||||
it.useMocha { }
|
||||
}
|
||||
|
||||
override fun configureRun(compilation: KotlinJsCompilation) {
|
||||
override fun configureMain(compilation: KotlinJsCompilation) {
|
||||
configureRun(compilation, null)
|
||||
configureBuild(compilation, null)
|
||||
}
|
||||
|
||||
override fun configureRun(
|
||||
compilation: KotlinJsCompilation,
|
||||
dceTaskProvider: TaskProvider<KotlinJsDce>?
|
||||
) {
|
||||
val runTaskHolder = NodeJsExec.create(compilation, disambiguateCamelCased("run"))
|
||||
target.runTask.dependsOn(runTaskHolder)
|
||||
}
|
||||
|
||||
override fun configureBuild(compilation: KotlinJsCompilation) {
|
||||
override fun configureBuild(
|
||||
compilation: KotlinJsCompilation,
|
||||
dceTaskProvider: TaskProvider<KotlinJsDce>?
|
||||
) {
|
||||
}
|
||||
|
||||
override fun configureBuildVariants() {
|
||||
|
||||
Reference in New Issue
Block a user