[Gradle, JS] Extract build task configuration from run task
This commit is contained in:
+20
-14
@@ -43,20 +43,7 @@ open class KotlinBrowserJs @Inject constructor(target: KotlinJsTarget) :
|
||||
val project = compilation.target.project
|
||||
val nodeJs = NodeJsRootPlugin.apply(project.rootProject)
|
||||
|
||||
project.registerTask<KotlinWebpack>(disambiguateCamelCased("webpack")) {
|
||||
val compileKotlinTask = compilation.compileKotlinTask
|
||||
it.dependsOn(
|
||||
nodeJs.npmInstallTask,
|
||||
compileKotlinTask
|
||||
)
|
||||
|
||||
it.compilation = compilation
|
||||
it.description = "build webpack bundle"
|
||||
|
||||
project.tasks.getByName(LifecycleBasePlugin.ASSEMBLE_TASK_NAME).dependsOn(it)
|
||||
}
|
||||
|
||||
val run = project.registerTask<KotlinWebpack>(disambiguateCamelCased("run")) {
|
||||
val run = project.registerTask<KotlinWebpack>(runTaskName) {
|
||||
val compileKotlinTask = compilation.compileKotlinTask
|
||||
it.dependsOn(
|
||||
nodeJs.npmInstallTask,
|
||||
@@ -78,4 +65,23 @@ open class KotlinBrowserJs @Inject constructor(target: KotlinJsTarget) :
|
||||
|
||||
target.runTask.dependsOn(run)
|
||||
}
|
||||
|
||||
override fun configureBuild(compilation: KotlinJsCompilation) {
|
||||
val project = compilation.target.project
|
||||
val nodeJs = NodeJsRootPlugin.apply(project.rootProject)
|
||||
|
||||
project.registerTask<KotlinWebpack>(webpackTaskName) {
|
||||
val compileKotlinTask = compilation.compileKotlinTask
|
||||
it.dependsOn(
|
||||
nodeJs.npmInstallTask,
|
||||
compileKotlinTask
|
||||
)
|
||||
|
||||
it.compilation = compilation
|
||||
it.description = "build webpack bundle"
|
||||
|
||||
project.tasks.getByName(LifecycleBasePlugin.ASSEMBLE_TASK_NAME).dependsOn(it)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+14
-9
@@ -8,7 +8,9 @@ package org.jetbrains.kotlin.gradle.targets.js.subtargets
|
||||
import org.gradle.api.NamedDomainObjectContainer
|
||||
import org.gradle.api.plugins.ExtensionAware
|
||||
import org.gradle.language.base.plugins.LifecycleBasePlugin
|
||||
import org.jetbrains.kotlin.gradle.plugin.*
|
||||
import org.jetbrains.kotlin.gradle.plugin.AbstractKotlinTargetConfigurator
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinTargetWithTests
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJsCompilation
|
||||
import org.jetbrains.kotlin.gradle.plugin.whenEvaluated
|
||||
import org.jetbrains.kotlin.gradle.targets.js.KotlinJsPlatformTestRun
|
||||
@@ -33,6 +35,8 @@ abstract class KotlinJsSubTarget(
|
||||
val runTaskName = disambiguateCamelCased("run")
|
||||
val testTaskName = disambiguateCamelCased("test")
|
||||
|
||||
abstract val testTaskDescription: String
|
||||
|
||||
final override lateinit var testRuns: NamedDomainObjectContainer<KotlinJsPlatformTestRun>
|
||||
private set
|
||||
|
||||
@@ -40,7 +44,8 @@ abstract class KotlinJsSubTarget(
|
||||
NpmResolverPlugin.apply(project)
|
||||
|
||||
configureTests()
|
||||
configureRun()
|
||||
configure { configureRun(it) }
|
||||
configure { configureBuild(it) }
|
||||
|
||||
target.compilations.all {
|
||||
val npmProject = it.npmProject
|
||||
@@ -48,6 +53,10 @@ abstract class KotlinJsSubTarget(
|
||||
}
|
||||
}
|
||||
|
||||
override fun testTask(body: KotlinJsTest.() -> Unit) {
|
||||
testRuns.getByName(KotlinTargetWithTests.DEFAULT_TEST_RUN_NAME).executionTask.configure(body)
|
||||
}
|
||||
|
||||
protected fun disambiguateCamelCased(name: String): String =
|
||||
lowerCamelCaseName(target.disambiguationClassifier, disambiguationClassifier, name)
|
||||
|
||||
@@ -66,8 +75,6 @@ abstract class KotlinJsSubTarget(
|
||||
}
|
||||
}
|
||||
|
||||
abstract val testTaskDescription: String
|
||||
|
||||
private fun configureTestsRun(testRun: KotlinJsPlatformTestRun, compilation: KotlinJsCompilation) {
|
||||
fun KotlinJsPlatformTestRun.subtargetTestTaskName(): String = disambiguateCamelCased(
|
||||
lowerCamelCaseName(
|
||||
@@ -116,17 +123,15 @@ abstract class KotlinJsSubTarget(
|
||||
|
||||
protected abstract fun configureDefaultTestFramework(it: KotlinJsTest)
|
||||
|
||||
fun configureRun() {
|
||||
fun configure(configurator: (KotlinJsCompilation) -> Unit) {
|
||||
target.compilations.all { compilation ->
|
||||
if (compilation.name == KotlinCompilation.MAIN_COMPILATION_NAME) {
|
||||
configureRun(compilation)
|
||||
configurator(compilation)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract fun configureRun(compilation: KotlinJsCompilation)
|
||||
|
||||
override fun testTask(body: KotlinJsTest.() -> Unit) {
|
||||
testRuns.getByName(KotlinTargetWithTests.DEFAULT_TEST_RUN_NAME).executionTask.configure(body)
|
||||
}
|
||||
protected abstract fun configureBuild(compilation: KotlinJsCompilation)
|
||||
}
|
||||
+3
-1
@@ -15,7 +15,6 @@ import javax.inject.Inject
|
||||
open class KotlinNodeJs @Inject constructor(target: KotlinJsTarget) :
|
||||
KotlinJsSubTarget(target, "node"),
|
||||
KotlinJsNodeDsl {
|
||||
|
||||
override val testTaskDescription: String
|
||||
get() = "Run all ${target.name} tests inside nodejs using the builtin test framework"
|
||||
|
||||
@@ -31,4 +30,7 @@ open class KotlinNodeJs @Inject constructor(target: KotlinJsTarget) :
|
||||
val runTaskHolder = NodeJsExec.create(compilation, disambiguateCamelCased("run"))
|
||||
target.runTask.dependsOn(runTaskHolder)
|
||||
}
|
||||
|
||||
override fun configureBuild(compilation: KotlinJsCompilation) {
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user