[Gradle, JS] Add BuildVariants
This commit is contained in:
+21
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.gradle.targets.js.dsl
|
||||
|
||||
import org.gradle.api.Named
|
||||
|
||||
class BuildVariant(private val name: String) : Named {
|
||||
var kind: BuildVariantKind = BuildVariantKind.RELEASE
|
||||
|
||||
override fun getName(): String {
|
||||
return name
|
||||
}
|
||||
}
|
||||
|
||||
enum class BuildVariantKind {
|
||||
RELEASE,
|
||||
DEBUG
|
||||
}
|
||||
+6
-1
@@ -8,8 +8,8 @@ package org.jetbrains.kotlin.gradle.targets.js.dsl
|
||||
import groovy.lang.Closure
|
||||
import org.gradle.api.NamedDomainObjectContainer
|
||||
import org.gradle.util.ConfigureUtil
|
||||
import org.jetbrains.kotlin.gradle.targets.js.KotlinJsReportAggregatingTestRun
|
||||
import org.jetbrains.kotlin.gradle.targets.js.KotlinJsPlatformTestRun
|
||||
import org.jetbrains.kotlin.gradle.targets.js.KotlinJsReportAggregatingTestRun
|
||||
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsExec
|
||||
import org.jetbrains.kotlin.gradle.targets.js.testing.KotlinJsTest
|
||||
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpack
|
||||
@@ -59,6 +59,11 @@ interface KotlinJsBrowserDsl : KotlinJsSubTargetDsl {
|
||||
ConfigureUtil.configure(fn, this)
|
||||
}
|
||||
}
|
||||
|
||||
val buildVariants: NamedDomainObjectContainer<BuildVariant>
|
||||
|
||||
fun NamedDomainObjectContainer<BuildVariant>.release(body: BuildVariant.() -> Unit)
|
||||
fun NamedDomainObjectContainer<BuildVariant>.debug(body: BuildVariant.() -> Unit)
|
||||
}
|
||||
|
||||
interface KotlinJsNodeDsl : KotlinJsSubTargetDsl {
|
||||
|
||||
+47
-9
@@ -5,21 +5,27 @@
|
||||
|
||||
package org.jetbrains.kotlin.gradle.targets.js.subtargets
|
||||
|
||||
import org.gradle.api.NamedDomainObjectContainer
|
||||
import org.gradle.language.base.plugins.LifecycleBasePlugin
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJsCompilation
|
||||
import org.jetbrains.kotlin.gradle.targets.js.KotlinJsTarget
|
||||
import org.jetbrains.kotlin.gradle.targets.js.dsl.BuildVariant
|
||||
import org.jetbrains.kotlin.gradle.targets.js.dsl.BuildVariantKind
|
||||
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsBrowserDsl
|
||||
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin
|
||||
import org.jetbrains.kotlin.gradle.targets.js.testing.KotlinJsTest
|
||||
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpack
|
||||
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackConfig
|
||||
import org.jetbrains.kotlin.gradle.tasks.registerTask
|
||||
import org.jetbrains.kotlin.gradle.utils.lowerCamelCaseName
|
||||
import javax.inject.Inject
|
||||
|
||||
open class KotlinBrowserJs @Inject constructor(target: KotlinJsTarget) :
|
||||
KotlinJsSubTarget(target, "browser"),
|
||||
KotlinJsBrowserDsl {
|
||||
|
||||
override lateinit var buildVariants: NamedDomainObjectContainer<BuildVariant>
|
||||
|
||||
override val testTaskDescription: String
|
||||
get() = "Run all ${target.name} tests inside browser using karma and webpack"
|
||||
|
||||
@@ -39,7 +45,16 @@ open class KotlinBrowserJs @Inject constructor(target: KotlinJsTarget) :
|
||||
(project.tasks.getByName(webpackTaskName) as KotlinWebpack).body()
|
||||
}
|
||||
|
||||
override fun NamedDomainObjectContainer<BuildVariant>.release(body: BuildVariant.() -> Unit) {
|
||||
buildVariants.getByName(RELEASE).body()
|
||||
}
|
||||
|
||||
override fun NamedDomainObjectContainer<BuildVariant>.debug(body: BuildVariant.() -> Unit) {
|
||||
buildVariants.getByName(DEBUG).body()
|
||||
}
|
||||
|
||||
override fun configureRun(compilation: KotlinJsCompilation) {
|
||||
|
||||
val project = compilation.target.project
|
||||
val nodeJs = NodeJsRootPlugin.apply(project.rootProject)
|
||||
|
||||
@@ -70,18 +85,41 @@ open class KotlinBrowserJs @Inject constructor(target: KotlinJsTarget) :
|
||||
val project = compilation.target.project
|
||||
val nodeJs = NodeJsRootPlugin.apply(project.rootProject)
|
||||
|
||||
project.registerTask<KotlinWebpack>(webpackTaskName) {
|
||||
val compileKotlinTask = compilation.compileKotlinTask
|
||||
it.dependsOn(
|
||||
nodeJs.npmInstallTask,
|
||||
compileKotlinTask
|
||||
)
|
||||
buildVariants.all { buildVariant ->
|
||||
project.registerTask<KotlinWebpack>(
|
||||
disambiguateCamelCased(
|
||||
lowerCamelCaseName(
|
||||
buildVariant.name,
|
||||
"webpack"
|
||||
)
|
||||
)
|
||||
) {
|
||||
val compileKotlinTask = compilation.compileKotlinTask
|
||||
it.dependsOn(
|
||||
nodeJs.npmInstallTask,
|
||||
compileKotlinTask
|
||||
)
|
||||
|
||||
it.compilation = compilation
|
||||
it.description = "build webpack bundle"
|
||||
it.compilation = compilation
|
||||
it.description = "build webpack bundle"
|
||||
|
||||
project.tasks.getByName(LifecycleBasePlugin.ASSEMBLE_TASK_NAME).dependsOn(it)
|
||||
project.tasks.getByName(LifecycleBasePlugin.ASSEMBLE_TASK_NAME).dependsOn(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun configureBuildVariants() {
|
||||
buildVariants = project.container(BuildVariant::class.java)
|
||||
buildVariants.create(RELEASE) {
|
||||
it.kind = BuildVariantKind.RELEASE
|
||||
}
|
||||
buildVariants.create(DEBUG) {
|
||||
it.kind = BuildVariantKind.DEBUG
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val RELEASE = "release"
|
||||
const val DEBUG = "debug"
|
||||
}
|
||||
}
|
||||
+3
@@ -43,6 +43,7 @@ abstract class KotlinJsSubTarget(
|
||||
fun configure() {
|
||||
NpmResolverPlugin.apply(project)
|
||||
|
||||
configureBuildVariants()
|
||||
configureTests()
|
||||
configure { configureRun(it) }
|
||||
configure { configureBuild(it) }
|
||||
@@ -60,6 +61,8 @@ abstract class KotlinJsSubTarget(
|
||||
protected fun disambiguateCamelCased(name: String): String =
|
||||
lowerCamelCaseName(target.disambiguationClassifier, disambiguationClassifier, name)
|
||||
|
||||
abstract fun configureBuildVariants()
|
||||
|
||||
private fun configureTests() {
|
||||
testRuns = project.container(KotlinJsPlatformTestRun::class.java) { name -> KotlinJsPlatformTestRun(name, this) }.also {
|
||||
(this as ExtensionAware).extensions.add(this::testRuns.name, it)
|
||||
|
||||
+3
@@ -33,4 +33,7 @@ open class KotlinNodeJs @Inject constructor(target: KotlinJsTarget) :
|
||||
|
||||
override fun configureBuild(compilation: KotlinJsCompilation) {
|
||||
}
|
||||
|
||||
override fun configureBuildVariants() {
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user