[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 {
|
private val browserLazyDelegate = lazy {
|
||||||
project.objects.newInstance(KotlinBrowserJs::class.java, this).also {
|
project.objects.newInstance(KotlinBrowserJs::class.java, this).also {
|
||||||
it.configure()
|
browserConfiguredHandlers.forEach { handler ->
|
||||||
browserConfiguredHandlers.forEach { handler -> handler(it) }
|
it.whenProducingConfigured {
|
||||||
|
handler(this)
|
||||||
|
}
|
||||||
|
}
|
||||||
browserConfiguredHandlers.clear()
|
browserConfiguredHandlers.clear()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -126,8 +129,12 @@ constructor(
|
|||||||
|
|
||||||
private val nodejsLazyDelegate = lazy {
|
private val nodejsLazyDelegate = lazy {
|
||||||
project.objects.newInstance(KotlinNodeJs::class.java, this).also {
|
project.objects.newInstance(KotlinNodeJs::class.java, this).also {
|
||||||
it.configure()
|
nodejsConfiguredHandlers.forEach { handler ->
|
||||||
nodejsConfiguredHandlers.forEach { handler -> handler(it) }
|
it.whenProducingConfigured {
|
||||||
|
handler(this)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
nodejsConfiguredHandlers.clear()
|
nodejsConfiguredHandlers.clear()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
@@ -66,6 +66,10 @@ interface KotlinJsSubTargetDsl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun produceKotlinLibrary()
|
||||||
|
|
||||||
|
fun produceExecutable()
|
||||||
|
|
||||||
val testRuns: NamedDomainObjectContainer<KotlinJsPlatformTestRun>
|
val testRuns: NamedDomainObjectContainer<KotlinJsPlatformTestRun>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+15
@@ -43,6 +43,13 @@ open class KotlinBrowserJs @Inject constructor(target: KotlinJsTarget) :
|
|||||||
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"
|
||||||
|
|
||||||
|
override fun configure() {
|
||||||
|
super.configure()
|
||||||
|
browserProducingConfiguredHandlers.forEach { handler ->
|
||||||
|
handler(this)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun configureDefaultTestFramework(testTask: KotlinJsTest) {
|
override fun configureDefaultTestFramework(testTask: KotlinJsTest) {
|
||||||
testTask.useKarma {
|
testTask.useKarma {
|
||||||
useChromeHeadless()
|
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 {
|
companion object {
|
||||||
const val DCE_TASK_PREFIX = "processDce"
|
const val DCE_TASK_PREFIX = "processDce"
|
||||||
const val DCE_TASK_SUFFIX = "kotlinJs"
|
const val DCE_TASK_SUFFIX = "kotlinJs"
|
||||||
|
|||||||
+17
-3
@@ -37,12 +37,26 @@ abstract class KotlinJsSubTarget(
|
|||||||
final override lateinit var testRuns: NamedDomainObjectContainer<KotlinJsPlatformTestRun>
|
final override lateinit var testRuns: NamedDomainObjectContainer<KotlinJsPlatformTestRun>
|
||||||
private set
|
private set
|
||||||
|
|
||||||
fun configure() {
|
protected val producingConfigured: Boolean = false
|
||||||
NpmResolverPlugin.apply(project)
|
|
||||||
|
protected val browserProducingConfiguredHandlers: MutableList<KotlinBrowserJs.() -> Unit> = mutableListOf()
|
||||||
|
protected val nodejsProducingConfiguredHandlers: MutableList<KotlinNodeJs.() -> Unit> = mutableListOf()
|
||||||
|
|
||||||
|
override fun produceKotlinLibrary() {
|
||||||
|
configure()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun produceExecutable() {
|
||||||
|
configure()
|
||||||
|
|
||||||
configureBuildVariants()
|
configureBuildVariants()
|
||||||
configureTests()
|
|
||||||
configureMain()
|
configureMain()
|
||||||
|
}
|
||||||
|
|
||||||
|
protected open fun configure() {
|
||||||
|
NpmResolverPlugin.apply(project)
|
||||||
|
|
||||||
|
configureTests()
|
||||||
|
|
||||||
target.compilations.all {
|
target.compilations.all {
|
||||||
val npmProject = it.npmProject
|
val npmProject = it.npmProject
|
||||||
|
|||||||
+15
@@ -20,6 +20,13 @@ open class KotlinNodeJs @Inject constructor(target: KotlinJsTarget) :
|
|||||||
|
|
||||||
private val runTaskName = disambiguateCamelCased("run")
|
private val runTaskName = disambiguateCamelCased("run")
|
||||||
|
|
||||||
|
override fun configure() {
|
||||||
|
super.configure()
|
||||||
|
nodejsProducingConfiguredHandlers.forEach { handler ->
|
||||||
|
handler(this)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun runTask(body: NodeJsExec.() -> Unit) {
|
override fun runTask(body: NodeJsExec.() -> Unit) {
|
||||||
(project.tasks.getByName(runTaskName) as NodeJsExec).body()
|
(project.tasks.getByName(runTaskName) as NodeJsExec).body()
|
||||||
}
|
}
|
||||||
@@ -43,4 +50,12 @@ open class KotlinNodeJs @Inject constructor(target: KotlinJsTarget) :
|
|||||||
|
|
||||||
override fun configureBuildVariants() {
|
override fun configureBuildVariants() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun whenProducingConfigured(body: KotlinNodeJs.() -> Unit) {
|
||||||
|
if (producingConfigured) {
|
||||||
|
this.body()
|
||||||
|
} else {
|
||||||
|
nodejsProducingConfiguredHandlers += body
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user