[Gradle, JS] Cartesian product of build variant and task types
This commit is contained in:
-5
@@ -59,11 +59,6 @@ interface KotlinJsBrowserDsl : KotlinJsSubTargetDsl {
|
|||||||
ConfigureUtil.configure(fn, this)
|
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 {
|
interface KotlinJsNodeDsl : KotlinJsSubTargetDsl {
|
||||||
|
|||||||
+55
-42
@@ -26,7 +26,7 @@ open class KotlinBrowserJs @Inject constructor(target: KotlinJsTarget) :
|
|||||||
KotlinJsSubTarget(target, "browser"),
|
KotlinJsSubTarget(target, "browser"),
|
||||||
KotlinJsBrowserDsl {
|
KotlinJsBrowserDsl {
|
||||||
|
|
||||||
override lateinit var buildVariants: NamedDomainObjectContainer<BuildVariant>
|
lateinit var buildVariants: NamedDomainObjectContainer<BuildVariant>
|
||||||
|
|
||||||
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"
|
||||||
@@ -47,40 +47,46 @@ open class KotlinBrowserJs @Inject constructor(target: KotlinJsTarget) :
|
|||||||
(project.tasks.getByName(webpackTaskName) as KotlinWebpack).body()
|
(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) {
|
override fun configureRun(compilation: KotlinJsCompilation) {
|
||||||
|
|
||||||
val project = compilation.target.project
|
val project = compilation.target.project
|
||||||
val nodeJs = NodeJsRootPlugin.apply(project.rootProject)
|
val nodeJs = NodeJsRootPlugin.apply(project.rootProject)
|
||||||
|
|
||||||
val run = project.registerTask<KotlinWebpack>(runTaskName) {
|
buildVariants.all { buildVariant ->
|
||||||
val compileKotlinTask = compilation.compileKotlinTask
|
val kind = buildVariant.kind
|
||||||
it.dependsOn(
|
val run = project.registerTask<KotlinWebpack>(
|
||||||
nodeJs.npmInstallTask,
|
disambiguateCamelCased(
|
||||||
compileKotlinTask,
|
lowerCamelCaseName(
|
||||||
target.project.tasks.getByName(compilation.processResourcesTaskName)
|
buildVariant.name,
|
||||||
)
|
"run"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
val compileKotlinTask = compilation.compileKotlinTask
|
||||||
|
it.dependsOn(
|
||||||
|
nodeJs.npmInstallTask,
|
||||||
|
compileKotlinTask,
|
||||||
|
target.project.tasks.getByName(compilation.processResourcesTaskName)
|
||||||
|
)
|
||||||
|
|
||||||
it.bin = "webpack-dev-server/bin/webpack-dev-server.js"
|
it.configureOptimization(kind)
|
||||||
it.compilation = compilation
|
|
||||||
it.description = "start webpack dev server"
|
|
||||||
|
|
||||||
it.devServer = KotlinWebpackConfig.DevServer(
|
it.bin = "webpack-dev-server/bin/webpack-dev-server.js"
|
||||||
open = true,
|
it.compilation = compilation
|
||||||
contentBase = listOf(compilation.output.resourcesDir.canonicalPath)
|
it.description = "start ${kind.name.toLowerCase()} webpack dev server"
|
||||||
)
|
|
||||||
|
|
||||||
it.outputs.upToDateWhen { false }
|
it.devServer = KotlinWebpackConfig.DevServer(
|
||||||
|
open = true,
|
||||||
|
contentBase = listOf(compilation.output.resourcesDir.canonicalPath)
|
||||||
|
)
|
||||||
|
|
||||||
|
it.outputs.upToDateWhen { false }
|
||||||
|
}
|
||||||
|
|
||||||
|
if (kind == BuildVariantKind.DEBUG) {
|
||||||
|
target.runTask.dependsOn(run)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
target.runTask.dependsOn(run)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun configureBuild(compilation: KotlinJsCompilation) {
|
override fun configureBuild(compilation: KotlinJsCompilation) {
|
||||||
@@ -88,7 +94,8 @@ open class KotlinBrowserJs @Inject constructor(target: KotlinJsTarget) :
|
|||||||
val nodeJs = NodeJsRootPlugin.apply(project.rootProject)
|
val nodeJs = NodeJsRootPlugin.apply(project.rootProject)
|
||||||
|
|
||||||
buildVariants.all { buildVariant ->
|
buildVariants.all { buildVariant ->
|
||||||
project.registerTask<KotlinWebpack>(
|
val kind = buildVariant.kind
|
||||||
|
val build = project.registerTask<KotlinWebpack>(
|
||||||
disambiguateCamelCased(
|
disambiguateCamelCased(
|
||||||
lowerCamelCaseName(
|
lowerCamelCaseName(
|
||||||
buildVariant.name,
|
buildVariant.name,
|
||||||
@@ -102,28 +109,34 @@ open class KotlinBrowserJs @Inject constructor(target: KotlinJsTarget) :
|
|||||||
compileKotlinTask
|
compileKotlinTask
|
||||||
)
|
)
|
||||||
|
|
||||||
val kind = buildVariant.kind
|
it.configureOptimization(kind)
|
||||||
|
|
||||||
it.mode = getByKind(
|
|
||||||
kind = kind,
|
|
||||||
releaseValue = Mode.PRODUCTION,
|
|
||||||
debugValue = Mode.DEVELOPMENT
|
|
||||||
)
|
|
||||||
|
|
||||||
it.devtool = getByKind(
|
|
||||||
kind = kind,
|
|
||||||
releaseValue = Devtool.SOURCE_MAP,
|
|
||||||
debugValue = Devtool.EVAL_SOURCE_MAP
|
|
||||||
)
|
|
||||||
|
|
||||||
it.compilation = compilation
|
it.compilation = compilation
|
||||||
it.description = "build webpack bundle"
|
it.description = "build webpack ${kind.name.toLowerCase()} bundle"
|
||||||
|
|
||||||
project.tasks.getByName(LifecycleBasePlugin.ASSEMBLE_TASK_NAME).dependsOn(it)
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (kind == BuildVariantKind.RELEASE) {
|
||||||
|
project.tasks.getByName(LifecycleBasePlugin.ASSEMBLE_TASK_NAME).dependsOn(build)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun KotlinWebpack.configureOptimization(kind: BuildVariantKind) {
|
||||||
|
mode = getByKind(
|
||||||
|
kind = kind,
|
||||||
|
releaseValue = Mode.PRODUCTION,
|
||||||
|
debugValue = Mode.DEVELOPMENT
|
||||||
|
)
|
||||||
|
|
||||||
|
devtool = getByKind(
|
||||||
|
kind = kind,
|
||||||
|
releaseValue = Devtool.SOURCE_MAP,
|
||||||
|
debugValue = Devtool.EVAL_SOURCE_MAP
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
private fun <T> getByKind(
|
private fun <T> getByKind(
|
||||||
kind: BuildVariantKind,
|
kind: BuildVariantKind,
|
||||||
releaseValue: T,
|
releaseValue: T,
|
||||||
|
|||||||
Reference in New Issue
Block a user