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
|
||||
|
||||
import org.gradle.api.DefaultTask
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.file.FileCollection
|
||||
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.deployment.internal.Deployment
|
||||
import org.gradle.deployment.internal.DeploymentHandle
|
||||
@@ -61,8 +64,51 @@ open class KotlinWebpack : DefaultTask(), RequiresNpmDependencies {
|
||||
@Input
|
||||
var saveEvaluatedConfigFile: Boolean = true
|
||||
|
||||
open val outputPath: File
|
||||
@OutputDirectory get() = project.buildDir.resolve("libs")
|
||||
@get:Internal
|
||||
@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?
|
||||
@Optional @InputDirectory get() = project.projectDir.resolve("webpack.config.d").takeIf { it.isDirectory }
|
||||
@@ -94,7 +140,8 @@ open class KotlinWebpack : DefaultTask(), RequiresNpmDependencies {
|
||||
KotlinWebpackConfigWriter(
|
||||
entry = entry,
|
||||
reportEvaluatedConfigFile = if (saveEvaluatedConfigFile) evaluatedConfigFile else null,
|
||||
outputPath = outputPath,
|
||||
outputPath = destinationDirectory,
|
||||
outputFileName = archiveFileName,
|
||||
configDirectory = configDirectory,
|
||||
bundleAnalyzerReportDir = if (report) reportDir else null,
|
||||
devServer = devServer,
|
||||
|
||||
+2
-1
@@ -19,6 +19,7 @@ data class KotlinWebpackConfigWriter(
|
||||
val mode: Mode = Mode.DEVELOPMENT,
|
||||
val entry: File? = null,
|
||||
val outputPath: File? = null,
|
||||
val outputFileName: String? = entry?.name,
|
||||
val configDirectory: File? = null,
|
||||
val bundleAnalyzerReportDir: File? = null,
|
||||
val reportEvaluatedConfigFile: File? = null,
|
||||
@@ -203,7 +204,7 @@ data class KotlinWebpackConfigWriter(
|
||||
config.entry.push(${jsQuotedString(entry.canonicalPath)});
|
||||
config.output = {
|
||||
path: ${jsQuotedString(outputPath.canonicalPath)},
|
||||
filename: ${jsQuotedString(entry.name)}
|
||||
filename: ${jsQuotedString(outputFileName!!)}
|
||||
};
|
||||
|
||||
""".trimIndent()
|
||||
|
||||
Reference in New Issue
Block a user