[Gradle, JS] Add additinal DSL (with KotlinLibrary or Executable) for mixed and legacy
This commit is contained in:
+11
-4
@@ -108,8 +108,11 @@ constructor(
|
||||
|
||||
private val browserLazyDelegate = lazy {
|
||||
project.objects.newInstance(KotlinBrowserJs::class.java, this).also {
|
||||
it.configure()
|
||||
browserConfiguredHandlers.forEach { handler -> handler(it) }
|
||||
browserConfiguredHandlers.forEach { handler ->
|
||||
it.whenProducingConfigured {
|
||||
handler(this)
|
||||
}
|
||||
}
|
||||
browserConfiguredHandlers.clear()
|
||||
}
|
||||
}
|
||||
@@ -126,8 +129,12 @@ constructor(
|
||||
|
||||
private val nodejsLazyDelegate = lazy {
|
||||
project.objects.newInstance(KotlinNodeJs::class.java, this).also {
|
||||
it.configure()
|
||||
nodejsConfiguredHandlers.forEach { handler -> handler(it) }
|
||||
nodejsConfiguredHandlers.forEach { handler ->
|
||||
it.whenProducingConfigured {
|
||||
handler(this)
|
||||
}
|
||||
}
|
||||
|
||||
nodejsConfiguredHandlers.clear()
|
||||
}
|
||||
}
|
||||
|
||||
+4
@@ -66,6 +66,10 @@ interface KotlinJsSubTargetDsl {
|
||||
}
|
||||
}
|
||||
|
||||
fun produceKotlinLibrary()
|
||||
|
||||
fun produceExecutable()
|
||||
|
||||
val testRuns: NamedDomainObjectContainer<KotlinJsPlatformTestRun>
|
||||
}
|
||||
|
||||
|
||||
+15
@@ -43,6 +43,13 @@ open class KotlinBrowserJs @Inject constructor(target: KotlinJsTarget) :
|
||||
override val testTaskDescription: String
|
||||
get() = "Run all ${target.name} tests inside browser using karma and webpack"
|
||||
|
||||
override fun configure() {
|
||||
super.configure()
|
||||
browserProducingConfiguredHandlers.forEach { handler ->
|
||||
handler(this)
|
||||
}
|
||||
}
|
||||
|
||||
override fun configureDefaultTestFramework(testTask: KotlinJsTest) {
|
||||
testTask.useKarma {
|
||||
useChromeHeadless()
|
||||
@@ -287,6 +294,14 @@ open class KotlinBrowserJs @Inject constructor(target: KotlinJsTarget) :
|
||||
}
|
||||
}
|
||||
|
||||
fun whenProducingConfigured(body: KotlinBrowserJs.() -> Unit) {
|
||||
if (producingConfigured) {
|
||||
this.body()
|
||||
} else {
|
||||
browserProducingConfiguredHandlers += body
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val DCE_TASK_PREFIX = "processDce"
|
||||
const val DCE_TASK_SUFFIX = "kotlinJs"
|
||||
|
||||
+17
-3
@@ -37,12 +37,26 @@ abstract class KotlinJsSubTarget(
|
||||
final override lateinit var testRuns: NamedDomainObjectContainer<KotlinJsPlatformTestRun>
|
||||
private set
|
||||
|
||||
fun configure() {
|
||||
NpmResolverPlugin.apply(project)
|
||||
protected val producingConfigured: Boolean = false
|
||||
|
||||
protected val browserProducingConfiguredHandlers: MutableList<KotlinBrowserJs.() -> Unit> = mutableListOf()
|
||||
protected val nodejsProducingConfiguredHandlers: MutableList<KotlinNodeJs.() -> Unit> = mutableListOf()
|
||||
|
||||
override fun produceKotlinLibrary() {
|
||||
configure()
|
||||
}
|
||||
|
||||
override fun produceExecutable() {
|
||||
configure()
|
||||
|
||||
configureBuildVariants()
|
||||
configureTests()
|
||||
configureMain()
|
||||
}
|
||||
|
||||
protected open fun configure() {
|
||||
NpmResolverPlugin.apply(project)
|
||||
|
||||
configureTests()
|
||||
|
||||
target.compilations.all {
|
||||
val npmProject = it.npmProject
|
||||
|
||||
+15
@@ -20,6 +20,13 @@ open class KotlinNodeJs @Inject constructor(target: KotlinJsTarget) :
|
||||
|
||||
private val runTaskName = disambiguateCamelCased("run")
|
||||
|
||||
override fun configure() {
|
||||
super.configure()
|
||||
nodejsProducingConfiguredHandlers.forEach { handler ->
|
||||
handler(this)
|
||||
}
|
||||
}
|
||||
|
||||
override fun runTask(body: NodeJsExec.() -> Unit) {
|
||||
(project.tasks.getByName(runTaskName) as NodeJsExec).body()
|
||||
}
|
||||
@@ -43,4 +50,12 @@ open class KotlinNodeJs @Inject constructor(target: KotlinJsTarget) :
|
||||
|
||||
override fun configureBuildVariants() {
|
||||
}
|
||||
|
||||
fun whenProducingConfigured(body: KotlinNodeJs.() -> Unit) {
|
||||
if (producingConfigured) {
|
||||
this.body()
|
||||
} else {
|
||||
nodejsProducingConfiguredHandlers += body
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user