[Gradle, JS] Browser with binaries
This commit is contained in:
+30
-49
@@ -8,7 +8,6 @@ package org.jetbrains.kotlin.gradle.targets.js.ir
|
|||||||
import org.gradle.api.NamedDomainObjectContainer
|
import org.gradle.api.NamedDomainObjectContainer
|
||||||
import org.gradle.api.Task
|
import org.gradle.api.Task
|
||||||
import org.gradle.api.plugins.BasePluginConvention
|
import org.gradle.api.plugins.BasePluginConvention
|
||||||
import org.gradle.api.provider.Provider
|
|
||||||
import org.gradle.api.tasks.Copy
|
import org.gradle.api.tasks.Copy
|
||||||
import org.gradle.language.base.plugins.LifecycleBasePlugin
|
import org.gradle.language.base.plugins.LifecycleBasePlugin
|
||||||
import org.jetbrains.kotlin.gradle.dsl.KotlinJsDce
|
import org.jetbrains.kotlin.gradle.dsl.KotlinJsDce
|
||||||
@@ -67,34 +66,29 @@ open class KotlinBrowserJsIr @Inject constructor(target: KotlinJsIrTarget) :
|
|||||||
val project = compilation.target.project
|
val project = compilation.target.project
|
||||||
val nodeJs = NodeJsRootPlugin.apply(project.rootProject)
|
val nodeJs = NodeJsRootPlugin.apply(project.rootProject)
|
||||||
|
|
||||||
buildVariants.all { buildVariant ->
|
val commonRunTask = project.registerTask<Task>(disambiguateCamelCased(RUN_TASK_NAME)) {}
|
||||||
val kind = buildVariant.kind
|
|
||||||
|
binaries.getBinaries(compilation).all { binary ->
|
||||||
|
val type = binary.type
|
||||||
|
|
||||||
val runTask = project.registerTask<KotlinWebpack>(
|
val runTask = project.registerTask<KotlinWebpack>(
|
||||||
disambiguateCamelCased(
|
disambiguateCamelCased(
|
||||||
buildVariant.name,
|
binary.name,
|
||||||
RUN_TASK_NAME
|
RUN_TASK_NAME
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
it.dependsOn(
|
it.dependsOn(
|
||||||
nodeJs.npmInstallTask,
|
nodeJs.npmInstallTask,
|
||||||
getByKind(
|
binary.linkTask,
|
||||||
kind,
|
|
||||||
compilation.productionLinkTask,
|
|
||||||
compilation.developmentLinkTask
|
|
||||||
),
|
|
||||||
target.project.tasks.getByName(compilation.processResourcesTaskName)
|
target.project.tasks.getByName(compilation.processResourcesTaskName)
|
||||||
)
|
)
|
||||||
|
|
||||||
it.configureOptimization(kind)
|
it.configureOptimization(type)
|
||||||
|
|
||||||
it.bin = "webpack-dev-server/bin/webpack-dev-server.js"
|
it.bin = "webpack-dev-server/bin/webpack-dev-server.js"
|
||||||
it.compilation = compilation
|
it.compilation = compilation
|
||||||
it.entry = getByKind(
|
it.entry = binary.linkTask.map { it.outputFile }.get()
|
||||||
kind,
|
it.description = "start ${type.name.toLowerCase()} webpack dev server"
|
||||||
compilation.productionLinkTask.map { it.outputFile },
|
|
||||||
compilation.developmentLinkTask.map { it.outputFile }
|
|
||||||
).get()
|
|
||||||
it.description = "start ${kind.name.toLowerCase()} webpack dev server"
|
|
||||||
|
|
||||||
it.devServer = KotlinWebpackConfig.DevServer(
|
it.devServer = KotlinWebpackConfig.DevServer(
|
||||||
open = true,
|
open = true,
|
||||||
@@ -108,9 +102,9 @@ open class KotlinBrowserJsIr @Inject constructor(target: KotlinJsIrTarget) :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (kind == BuildVariantKind.DEVELOPMENT) {
|
if (type == BuildVariantKind.DEVELOPMENT) {
|
||||||
target.runTask.dependsOn(runTask)
|
target.runTask.dependsOn(runTask)
|
||||||
project.registerTask<Task>(disambiguateCamelCased(RUN_TASK_NAME)) {
|
commonRunTask.configure {
|
||||||
it.dependsOn(runTask)
|
it.dependsOn(runTask)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -142,49 +136,45 @@ open class KotlinBrowserJsIr @Inject constructor(target: KotlinJsIrTarget) :
|
|||||||
val assembleTask = project.tasks.getByName(LifecycleBasePlugin.ASSEMBLE_TASK_NAME)
|
val assembleTask = project.tasks.getByName(LifecycleBasePlugin.ASSEMBLE_TASK_NAME)
|
||||||
assembleTask.dependsOn(distributeResourcesTask)
|
assembleTask.dependsOn(distributeResourcesTask)
|
||||||
|
|
||||||
buildVariants.all { buildVariant ->
|
val webpackCommonTask = project.registerTask<Task>(disambiguateCamelCased(WEBPACK_TASK_NAME)) {
|
||||||
val kind = buildVariant.kind
|
}
|
||||||
|
|
||||||
|
project.registerTask<Task>(disambiguateCamelCased(DISTRIBUTION_TASK_NAME)) {
|
||||||
|
it.dependsOn(webpackCommonTask)
|
||||||
|
it.dependsOn(distributeResourcesTask)
|
||||||
|
}
|
||||||
|
|
||||||
|
binaries.getBinaries(compilation).all { binary ->
|
||||||
|
val type = binary.type
|
||||||
val webpackTask = project.registerTask<KotlinWebpack>(
|
val webpackTask = project.registerTask<KotlinWebpack>(
|
||||||
disambiguateCamelCased(
|
disambiguateCamelCased(
|
||||||
buildVariant.name,
|
binary.name,
|
||||||
WEBPACK_TASK_NAME
|
WEBPACK_TASK_NAME
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
it.dependsOn(
|
it.dependsOn(
|
||||||
nodeJs.npmInstallTask,
|
nodeJs.npmInstallTask,
|
||||||
getByKind(
|
binary.linkTask,
|
||||||
kind,
|
|
||||||
compilation.productionLinkTask,
|
|
||||||
compilation.developmentLinkTask
|
|
||||||
),
|
|
||||||
distributeResourcesTask
|
distributeResourcesTask
|
||||||
)
|
)
|
||||||
|
|
||||||
it.configureOptimization(kind)
|
it.configureOptimization(type)
|
||||||
|
|
||||||
it.compilation = compilation
|
it.compilation = compilation
|
||||||
it.entry = getByKind(
|
it.entry = binary.linkTask.map { it.outputFile }.get()
|
||||||
kind,
|
it.description = "build webpack ${type.name.toLowerCase()} bundle"
|
||||||
compilation.productionLinkTask.map { it.outputFile },
|
it.destinationDirectory = distribution.directory
|
||||||
compilation.developmentLinkTask.map { it.outputFile }
|
|
||||||
).get()
|
|
||||||
it.description = "build webpack ${kind.name.toLowerCase()} bundle"
|
|
||||||
it.destinationDirectory = distribution.directory!!
|
|
||||||
|
|
||||||
commonWebpackConfigurations.forEach { configure ->
|
commonWebpackConfigurations.forEach { configure ->
|
||||||
it.configure()
|
it.configure()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (kind == BuildVariantKind.PRODUCTION) {
|
if (type == BuildVariantKind.PRODUCTION) {
|
||||||
assembleTask.dependsOn(webpackTask)
|
assembleTask.dependsOn(webpackTask)
|
||||||
val webpackCommonTask = project.registerTask<Task>(disambiguateCamelCased(WEBPACK_TASK_NAME)) {
|
webpackCommonTask.configure {
|
||||||
it.dependsOn(webpackTask)
|
it.dependsOn(webpackTask)
|
||||||
}
|
}
|
||||||
project.registerTask<Task>(disambiguateCamelCased(DISTRIBUTION_TASK_NAME)) {
|
|
||||||
it.dependsOn(webpackCommonTask)
|
|
||||||
it.dependsOn(distributeResourcesTask)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -212,15 +202,6 @@ open class KotlinBrowserJsIr @Inject constructor(target: KotlinJsIrTarget) :
|
|||||||
BuildVariantKind.DEVELOPMENT -> debugValue
|
BuildVariantKind.DEVELOPMENT -> debugValue
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun <T> getByKind(
|
|
||||||
kind: BuildVariantKind,
|
|
||||||
releaseValue: Provider<T>,
|
|
||||||
debugValue: Provider<T>
|
|
||||||
): Provider<T> = when (kind) {
|
|
||||||
BuildVariantKind.PRODUCTION -> releaseValue
|
|
||||||
BuildVariantKind.DEVELOPMENT -> debugValue
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun configureBuildVariants() {
|
override fun configureBuildVariants() {
|
||||||
buildVariants = project.container(BuildVariant::class.java)
|
buildVariants = project.container(BuildVariant::class.java)
|
||||||
buildVariants.create(PRODUCTION) {
|
buildVariants.create(PRODUCTION) {
|
||||||
|
|||||||
+8
-10
@@ -28,7 +28,6 @@ constructor(
|
|||||||
get() = target.project
|
get() = target.project
|
||||||
|
|
||||||
private val binaryNames = mutableSetOf<String>()
|
private val binaryNames = mutableSetOf<String>()
|
||||||
private val compilationToBinaries = mutableMapOf<KotlinJsCompilation, MutableSet<JsBinary>>()
|
|
||||||
|
|
||||||
private val defaultCompilation: KotlinJsCompilation
|
private val defaultCompilation: KotlinJsCompilation
|
||||||
get() = target.compilations.getByName(KotlinCompilation.MAIN_COMPILATION_NAME)
|
get() = target.compilations.getByName(KotlinCompilation.MAIN_COMPILATION_NAME)
|
||||||
@@ -50,13 +49,19 @@ constructor(
|
|||||||
create = ::TestExecutable
|
create = ::TestExecutable
|
||||||
)
|
)
|
||||||
|
|
||||||
|
internal fun getBinaries(
|
||||||
|
compilation: KotlinJsCompilation
|
||||||
|
): DomainObjectSet<JsBinary> =
|
||||||
|
matching { it.compilation == compilation }
|
||||||
|
|
||||||
internal fun getBinary(
|
internal fun getBinary(
|
||||||
compilation: KotlinJsCompilation,
|
compilation: KotlinJsCompilation,
|
||||||
buildVariantKind: BuildVariantKind
|
buildVariantKind: BuildVariantKind
|
||||||
): JsBinary =
|
): JsBinary =
|
||||||
compilationToBinaries.getValue(
|
getBinaries(
|
||||||
compilation
|
compilation
|
||||||
).single { it.type == buildVariantKind }
|
).matching { it.type == buildVariantKind }
|
||||||
|
.single()
|
||||||
|
|
||||||
|
|
||||||
private fun <T : JsBinary> createBinaries(
|
private fun <T : JsBinary> createBinaries(
|
||||||
@@ -77,13 +82,6 @@ constructor(
|
|||||||
|
|
||||||
val binary = create(name, buildVariantKind, compilation)
|
val binary = create(name, buildVariantKind, compilation)
|
||||||
add(binary)
|
add(binary)
|
||||||
with(compilationToBinaries[compilation]) {
|
|
||||||
if (this != null) {
|
|
||||||
add(binary)
|
|
||||||
} else {
|
|
||||||
compilationToBinaries[compilation] = mutableSetOf<JsBinary>(binary)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Allow accessing binaries as properties of the container in Groovy DSL.
|
// Allow accessing binaries as properties of the container in Groovy DSL.
|
||||||
if (this is ExtensionAware) {
|
if (this is ExtensionAware) {
|
||||||
extensions.add(binary.name, binary)
|
extensions.add(binary.name, binary)
|
||||||
|
|||||||
-23
@@ -6,38 +6,15 @@
|
|||||||
package org.jetbrains.kotlin.gradle.targets.js.ir
|
package org.jetbrains.kotlin.gradle.targets.js.ir
|
||||||
|
|
||||||
import org.gradle.api.file.SourceDirectorySet
|
import org.gradle.api.file.SourceDirectorySet
|
||||||
import org.gradle.api.tasks.TaskProvider
|
|
||||||
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation
|
|
||||||
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
|
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
|
||||||
import org.jetbrains.kotlin.gradle.plugin.KotlinTarget
|
import org.jetbrains.kotlin.gradle.plugin.KotlinTarget
|
||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJsCompilation
|
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJsCompilation
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.dsl.BuildVariantKind
|
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.dsl.BuildVariantKind.DEVELOPMENT
|
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.dsl.BuildVariantKind.PRODUCTION
|
|
||||||
import org.jetbrains.kotlin.gradle.utils.lowerCamelCaseName
|
import org.jetbrains.kotlin.gradle.utils.lowerCamelCaseName
|
||||||
|
|
||||||
class KotlinJsIrCompilation(
|
class KotlinJsIrCompilation(
|
||||||
target: KotlinTarget,
|
target: KotlinTarget,
|
||||||
name: String
|
name: String
|
||||||
) : KotlinJsCompilation(target, name) {
|
) : KotlinJsCompilation(target, name) {
|
||||||
val productionLinkTaskName: String = linkTaskName(PRODUCTION)
|
|
||||||
|
|
||||||
val productionLinkTask: TaskProvider<KotlinJsIrLink>
|
|
||||||
get() = target.project.tasks.named(productionLinkTaskName) as TaskProvider<KotlinJsIrLink>
|
|
||||||
|
|
||||||
val developmentLinkTaskName: String = linkTaskName(DEVELOPMENT)
|
|
||||||
|
|
||||||
val developmentLinkTask: TaskProvider<KotlinJsIrLink>
|
|
||||||
get() = target.project.tasks.named(developmentLinkTaskName) as TaskProvider<KotlinJsIrLink>
|
|
||||||
|
|
||||||
private fun linkTaskName(type: BuildVariantKind): String =
|
|
||||||
lowerCamelCaseName(
|
|
||||||
"compile",
|
|
||||||
type.name.toLowerCase(),
|
|
||||||
compilationName.takeIf { it != KotlinCompilation.MAIN_COMPILATION_NAME },
|
|
||||||
"Kotlin",
|
|
||||||
target.targetName
|
|
||||||
)
|
|
||||||
|
|
||||||
internal val allSources: MutableSet<SourceDirectorySet> = mutableSetOf()
|
internal val allSources: MutableSet<SourceDirectorySet> = mutableSetOf()
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -54,7 +54,7 @@ constructor(
|
|||||||
KotlinJsBinaryContainer::class.java,
|
KotlinJsBinaryContainer::class.java,
|
||||||
this,
|
this,
|
||||||
WrapUtil.toDomainObjectSet(JsBinary::class.java).apply {
|
WrapUtil.toDomainObjectSet(JsBinary::class.java).apply {
|
||||||
all {
|
matching { it is Executable }.all {
|
||||||
whenBrowserConfigured {
|
whenBrowserConfigured {
|
||||||
(this as KotlinJsIrSubTarget).produceExecutable()
|
(this as KotlinJsIrSubTarget).produceExecutable()
|
||||||
}
|
}
|
||||||
|
|||||||
-9
@@ -16,7 +16,6 @@ import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation
|
|||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJsCompilation
|
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJsCompilation
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.KotlinJsTarget
|
import org.jetbrains.kotlin.gradle.targets.js.KotlinJsTarget
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.dsl.*
|
import org.jetbrains.kotlin.gradle.targets.js.dsl.*
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinBrowserJsIr
|
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin
|
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.npm.npmProject
|
import org.jetbrains.kotlin.gradle.targets.js.npm.npmProject
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.testing.KotlinJsTest
|
import org.jetbrains.kotlin.gradle.targets.js.testing.KotlinJsTest
|
||||||
@@ -44,14 +43,6 @@ 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"
|
||||||
|
|
||||||
private val irBrowser: KotlinBrowserJsIr?
|
|
||||||
get() = target.irTarget?.browser
|
|
||||||
|
|
||||||
override fun produceExecutable() {
|
|
||||||
super.produceExecutable()
|
|
||||||
irBrowser?.produceExecutable()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun configureDefaultTestFramework(testTask: KotlinJsTest) {
|
override fun configureDefaultTestFramework(testTask: KotlinJsTest) {
|
||||||
testTask.useKarma {
|
testTask.useKarma {
|
||||||
useChromeHeadless()
|
useChromeHeadless()
|
||||||
|
|||||||
-9
@@ -8,7 +8,6 @@ package org.jetbrains.kotlin.gradle.targets.js.subtargets
|
|||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJsCompilation
|
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJsCompilation
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.KotlinJsTarget
|
import org.jetbrains.kotlin.gradle.targets.js.KotlinJsTarget
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsNodeDsl
|
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsNodeDsl
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinNodeJsIr
|
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsExec
|
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.testing.KotlinJsTest
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
@@ -21,14 +20,6 @@ open class KotlinNodeJs @Inject constructor(target: KotlinJsTarget) :
|
|||||||
|
|
||||||
private val runTaskName = disambiguateCamelCased("run")
|
private val runTaskName = disambiguateCamelCased("run")
|
||||||
|
|
||||||
private val irNodejs: KotlinNodeJsIr?
|
|
||||||
get() = target.irTarget?.nodejs
|
|
||||||
|
|
||||||
override fun produceExecutable() {
|
|
||||||
super.produceExecutable()
|
|
||||||
irNodejs?.produceExecutable()
|
|
||||||
}
|
|
||||||
|
|
||||||
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()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user