[Gradle, JS] Each task configure your own dceOutputFileApplier
This commit is contained in:
+22
-9
@@ -34,7 +34,6 @@ open class KotlinBrowserJs @Inject constructor(target: KotlinJsTarget) :
|
|||||||
KotlinJsBrowserDsl {
|
KotlinJsBrowserDsl {
|
||||||
|
|
||||||
private val dceConfigurations: MutableList<KotlinJsDce.() -> Unit> = mutableListOf()
|
private val dceConfigurations: MutableList<KotlinJsDce.() -> Unit> = mutableListOf()
|
||||||
private val dceWebpackEntryAppliers: MutableList<KotlinJsDce.(File) -> Unit> = mutableListOf()
|
|
||||||
|
|
||||||
private lateinit var buildVariants: NamedDomainObjectContainer<BuildVariant>
|
private lateinit var buildVariants: NamedDomainObjectContainer<BuildVariant>
|
||||||
|
|
||||||
@@ -75,6 +74,10 @@ open class KotlinBrowserJs @Inject constructor(target: KotlinJsTarget) :
|
|||||||
val project = compilation.target.project
|
val project = compilation.target.project
|
||||||
val nodeJs = NodeJsRootPlugin.apply(project.rootProject)
|
val nodeJs = NodeJsRootPlugin.apply(project.rootProject)
|
||||||
|
|
||||||
|
val compileKotlinTask = compilation.compileKotlinTask
|
||||||
|
|
||||||
|
val dceOutputFileAppliers: MutableList<KotlinJsDce.(File) -> Unit> = mutableListOf()
|
||||||
|
|
||||||
buildVariants.all { buildVariant ->
|
buildVariants.all { buildVariant ->
|
||||||
val kind = buildVariant.kind
|
val kind = buildVariant.kind
|
||||||
val runTask = project.registerTask<KotlinWebpack>(
|
val runTask = project.registerTask<KotlinWebpack>(
|
||||||
@@ -83,7 +86,6 @@ open class KotlinBrowserJs @Inject constructor(target: KotlinJsTarget) :
|
|||||||
"run"
|
"run"
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
val compileKotlinTask = compilation.compileKotlinTask
|
|
||||||
it.dependsOn(
|
it.dependsOn(
|
||||||
nodeJs.npmInstallTask,
|
nodeJs.npmInstallTask,
|
||||||
target.project.tasks.getByName(compilation.processResourcesTaskName)
|
target.project.tasks.getByName(compilation.processResourcesTaskName)
|
||||||
@@ -104,7 +106,7 @@ open class KotlinBrowserJs @Inject constructor(target: KotlinJsTarget) :
|
|||||||
|
|
||||||
when (kind) {
|
when (kind) {
|
||||||
BuildVariantKind.RELEASE -> {
|
BuildVariantKind.RELEASE -> {
|
||||||
dceWebpackEntryAppliers.add { file ->
|
dceOutputFileAppliers.add { file ->
|
||||||
it.entry = file
|
it.entry = file
|
||||||
}
|
}
|
||||||
it.resolveFromModulesFirst = true
|
it.resolveFromModulesFirst = true
|
||||||
@@ -116,6 +118,12 @@ open class KotlinBrowserJs @Inject constructor(target: KotlinJsTarget) :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dceTaskProvider.configure {
|
||||||
|
dceOutputFileAppliers.forEach { dceOutputFileApplier ->
|
||||||
|
it.dceOutputFileApplier(it.destinationDir.resolve(compileKotlinTask.outputFile.name))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (kind == BuildVariantKind.DEBUG) {
|
if (kind == BuildVariantKind.DEBUG) {
|
||||||
target.runTask.dependsOn(runTask)
|
target.runTask.dependsOn(runTask)
|
||||||
}
|
}
|
||||||
@@ -129,6 +137,10 @@ open class KotlinBrowserJs @Inject constructor(target: KotlinJsTarget) :
|
|||||||
val project = compilation.target.project
|
val project = compilation.target.project
|
||||||
val nodeJs = NodeJsRootPlugin.apply(project.rootProject)
|
val nodeJs = NodeJsRootPlugin.apply(project.rootProject)
|
||||||
|
|
||||||
|
val compileKotlinTask = compilation.compileKotlinTask
|
||||||
|
|
||||||
|
val dceOutputFileAppliers: MutableList<KotlinJsDce.(File) -> Unit> = mutableListOf()
|
||||||
|
|
||||||
buildVariants.all { buildVariant ->
|
buildVariants.all { buildVariant ->
|
||||||
val kind = buildVariant.kind
|
val kind = buildVariant.kind
|
||||||
val webpackTask = project.registerTask<KotlinWebpack>(
|
val webpackTask = project.registerTask<KotlinWebpack>(
|
||||||
@@ -138,7 +150,6 @@ open class KotlinBrowserJs @Inject constructor(target: KotlinJsTarget) :
|
|||||||
|
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
val compileKotlinTask = compilation.compileKotlinTask
|
|
||||||
it.dependsOn(
|
it.dependsOn(
|
||||||
nodeJs.npmInstallTask
|
nodeJs.npmInstallTask
|
||||||
)
|
)
|
||||||
@@ -150,7 +161,7 @@ open class KotlinBrowserJs @Inject constructor(target: KotlinJsTarget) :
|
|||||||
|
|
||||||
when (kind) {
|
when (kind) {
|
||||||
BuildVariantKind.RELEASE -> {
|
BuildVariantKind.RELEASE -> {
|
||||||
dceWebpackEntryAppliers.add { file ->
|
dceOutputFileAppliers.add { file ->
|
||||||
it.entry = file
|
it.entry = file
|
||||||
}
|
}
|
||||||
it.resolveFromModulesFirst = true
|
it.resolveFromModulesFirst = true
|
||||||
@@ -162,6 +173,12 @@ open class KotlinBrowserJs @Inject constructor(target: KotlinJsTarget) :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dceTaskProvider.configure {
|
||||||
|
dceOutputFileAppliers.forEach { dceOutputFileApplier ->
|
||||||
|
it.dceOutputFileApplier(it.destinationDir.resolve(compileKotlinTask.outputFile.name))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (kind == BuildVariantKind.RELEASE) {
|
if (kind == BuildVariantKind.RELEASE) {
|
||||||
project.tasks.getByName(LifecycleBasePlugin.ASSEMBLE_TASK_NAME).dependsOn(webpackTask)
|
project.tasks.getByName(LifecycleBasePlugin.ASSEMBLE_TASK_NAME).dependsOn(webpackTask)
|
||||||
}
|
}
|
||||||
@@ -193,10 +210,6 @@ open class KotlinBrowserJs @Inject constructor(target: KotlinJsTarget) :
|
|||||||
it.destinationDir = it.dceOptions.outputDirectory?.let { File(it) }
|
it.destinationDir = it.dceOptions.outputDirectory?.let { File(it) }
|
||||||
?: compilation.npmProject.dir.resolve(DCE_DIR)
|
?: compilation.npmProject.dir.resolve(DCE_DIR)
|
||||||
|
|
||||||
dceWebpackEntryAppliers.forEach { entryApplier ->
|
|
||||||
it.entryApplier(it.destinationDir.resolve(kotlinTask.outputFile.name))
|
|
||||||
}
|
|
||||||
|
|
||||||
it.source(kotlinTask.outputFile)
|
it.source(kotlinTask.outputFile)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user