Gradle, webpack: add conventional archive properties
#KT-31890 Fixed #KT-32209 Fixed
This commit is contained in:
+50
-3
@@ -6,8 +6,11 @@
|
|||||||
package org.jetbrains.kotlin.gradle.targets.js.webpack
|
package org.jetbrains.kotlin.gradle.targets.js.webpack
|
||||||
|
|
||||||
import org.gradle.api.DefaultTask
|
import org.gradle.api.DefaultTask
|
||||||
|
import org.gradle.api.Project
|
||||||
import org.gradle.api.file.FileCollection
|
import org.gradle.api.file.FileCollection
|
||||||
import org.gradle.api.internal.file.FileResolver
|
import org.gradle.api.internal.file.FileResolver
|
||||||
|
import org.gradle.api.plugins.BasePluginConvention
|
||||||
|
import org.gradle.api.reflect.TypeOf.typeOf
|
||||||
import org.gradle.api.tasks.*
|
import org.gradle.api.tasks.*
|
||||||
import org.gradle.deployment.internal.Deployment
|
import org.gradle.deployment.internal.Deployment
|
||||||
import org.gradle.deployment.internal.DeploymentHandle
|
import org.gradle.deployment.internal.DeploymentHandle
|
||||||
@@ -61,8 +64,51 @@ open class KotlinWebpack : DefaultTask(), RequiresNpmDependencies {
|
|||||||
@Input
|
@Input
|
||||||
var saveEvaluatedConfigFile: Boolean = true
|
var saveEvaluatedConfigFile: Boolean = true
|
||||||
|
|
||||||
open val outputPath: File
|
@get:Internal
|
||||||
@OutputDirectory get() = project.buildDir.resolve("libs")
|
@Deprecated("use destinationDirectory instead", ReplaceWith("destinationDirectory"))
|
||||||
|
val outputPath: File
|
||||||
|
get() = destinationDirectory!!
|
||||||
|
|
||||||
|
private val baseConventions: BasePluginConvention?
|
||||||
|
get() = project.convention.plugins["base"] as BasePluginConvention?
|
||||||
|
|
||||||
|
@get:Internal
|
||||||
|
var destinationDirectory: File? = null
|
||||||
|
get() = field ?: project.buildDir.resolve(baseConventions!!.distsDirName)
|
||||||
|
|
||||||
|
@get:Internal
|
||||||
|
var archiveBaseName: String? = null
|
||||||
|
get() = field ?: baseConventions?.archivesBaseName
|
||||||
|
|
||||||
|
@get:Internal
|
||||||
|
var archiveAppendix: String? = null
|
||||||
|
|
||||||
|
@get:Internal
|
||||||
|
var archiveVersion: String? = null
|
||||||
|
get() = field ?: project.version.toString()
|
||||||
|
|
||||||
|
@get:Internal
|
||||||
|
var archiveClassifier: String? = null
|
||||||
|
|
||||||
|
@get:Internal
|
||||||
|
var archiveExtension: String? = "js"
|
||||||
|
|
||||||
|
@get:Internal
|
||||||
|
var archiveFileName: String? = null
|
||||||
|
get() = field ?: defaultArchiveFileName
|
||||||
|
|
||||||
|
private val defaultArchiveFileName: String
|
||||||
|
get() {
|
||||||
|
// [baseName]-[appendix]-[version]-[classifier].[extension]
|
||||||
|
val baseFileName = listOf(archiveBaseName, archiveAppendix, archiveVersion, archiveClassifier)
|
||||||
|
.filter { it != null && it.isNotBlank() }
|
||||||
|
.joinToString("-")
|
||||||
|
return baseFileName + if (archiveExtension == null) "" else ".$archiveExtension"
|
||||||
|
}
|
||||||
|
|
||||||
|
@get:OutputFile
|
||||||
|
open val archiveFile: File
|
||||||
|
get() = destinationDirectory!!.resolve(archiveFileName!!)
|
||||||
|
|
||||||
open val configDirectory: File?
|
open val configDirectory: File?
|
||||||
@Optional @InputDirectory get() = project.projectDir.resolve("webpack.config.d").takeIf { it.isDirectory }
|
@Optional @InputDirectory get() = project.projectDir.resolve("webpack.config.d").takeIf { it.isDirectory }
|
||||||
@@ -94,7 +140,8 @@ open class KotlinWebpack : DefaultTask(), RequiresNpmDependencies {
|
|||||||
KotlinWebpackConfigWriter(
|
KotlinWebpackConfigWriter(
|
||||||
entry = entry,
|
entry = entry,
|
||||||
reportEvaluatedConfigFile = if (saveEvaluatedConfigFile) evaluatedConfigFile else null,
|
reportEvaluatedConfigFile = if (saveEvaluatedConfigFile) evaluatedConfigFile else null,
|
||||||
outputPath = outputPath,
|
outputPath = destinationDirectory,
|
||||||
|
outputFileName = archiveFileName,
|
||||||
configDirectory = configDirectory,
|
configDirectory = configDirectory,
|
||||||
bundleAnalyzerReportDir = if (report) reportDir else null,
|
bundleAnalyzerReportDir = if (report) reportDir else null,
|
||||||
devServer = devServer,
|
devServer = devServer,
|
||||||
|
|||||||
+2
-1
@@ -19,6 +19,7 @@ data class KotlinWebpackConfigWriter(
|
|||||||
val mode: Mode = Mode.DEVELOPMENT,
|
val mode: Mode = Mode.DEVELOPMENT,
|
||||||
val entry: File? = null,
|
val entry: File? = null,
|
||||||
val outputPath: File? = null,
|
val outputPath: File? = null,
|
||||||
|
val outputFileName: String? = entry?.name,
|
||||||
val configDirectory: File? = null,
|
val configDirectory: File? = null,
|
||||||
val bundleAnalyzerReportDir: File? = null,
|
val bundleAnalyzerReportDir: File? = null,
|
||||||
val reportEvaluatedConfigFile: File? = null,
|
val reportEvaluatedConfigFile: File? = null,
|
||||||
@@ -203,7 +204,7 @@ data class KotlinWebpackConfigWriter(
|
|||||||
config.entry.push(${jsQuotedString(entry.canonicalPath)});
|
config.entry.push(${jsQuotedString(entry.canonicalPath)});
|
||||||
config.output = {
|
config.output = {
|
||||||
path: ${jsQuotedString(outputPath.canonicalPath)},
|
path: ${jsQuotedString(outputPath.canonicalPath)},
|
||||||
filename: ${jsQuotedString(entry.name)}
|
filename: ${jsQuotedString(outputFileName!!)}
|
||||||
};
|
};
|
||||||
|
|
||||||
""".trimIndent()
|
""".trimIndent()
|
||||||
|
|||||||
Reference in New Issue
Block a user