auto package.json version update
This commit is contained in:
parent
51918a2fb2
commit
babe0161ae
4 changed files with 73 additions and 18 deletions
|
|
@ -1,8 +1,17 @@
|
|||
import com.github.gradle.node.npm.task.NpmTask
|
||||
import dev.adamko.factoriowebmap.configurations.asConsumer
|
||||
import dev.adamko.factoriowebmap.configurations.typescriptAttributes
|
||||
import groovy.json.JsonOutput
|
||||
import kotlinx.serialization.encodeToString
|
||||
import kotlinx.serialization.json.Json
|
||||
import kotlinx.serialization.json.JsonObject
|
||||
import kotlinx.serialization.json.JsonPrimitive
|
||||
import kotlinx.serialization.json.jsonObject
|
||||
import kotlinx.serialization.json.jsonPrimitive
|
||||
import org.apache.tools.ant.filters.ReplaceTokens
|
||||
import org.gradle.kotlin.dsl.support.useToRun
|
||||
import org.jetbrains.kotlin.util.parseSpaceSeparatedArgs
|
||||
import org.jetbrains.kotlin.util.suffixIfNot
|
||||
|
||||
plugins {
|
||||
idea
|
||||
|
|
@ -55,6 +64,55 @@ val tstlTask = tasks.register<NpmTask>("typescriptToLua") {
|
|||
|
||||
}
|
||||
|
||||
val updatePackageJsonVersion by tasks.registering {
|
||||
group = project.name
|
||||
description = """
|
||||
Read the package.json file and set the version to be the project's version.
|
||||
""".trimIndent()
|
||||
|
||||
val projectVersion = "${project.version}"
|
||||
inputs.properties(
|
||||
"projectVersion" to projectVersion,
|
||||
)
|
||||
|
||||
val packageJsonFile = layout.projectDirectory.file("src/main/typescript/package.json")
|
||||
outputs.file(packageJsonFile)
|
||||
|
||||
val jsonFormatter = Json {
|
||||
prettyPrint = true
|
||||
prettyPrintIndent = " "
|
||||
}
|
||||
|
||||
onlyIf {
|
||||
val packageJsonContent = packageJsonFile.asFile.readText()
|
||||
val packageJson = jsonFormatter.parseToJsonElement(packageJsonContent).jsonObject
|
||||
packageJson["version"]?.jsonPrimitive?.content != projectVersion
|
||||
}
|
||||
|
||||
doFirst {
|
||||
delete(temporaryDir)
|
||||
mkdir(temporaryDir)
|
||||
}
|
||||
|
||||
doLast {
|
||||
val packageJsonContent = packageJsonFile.asFile.readText()
|
||||
val packageJson = jsonFormatter.parseToJsonElement(packageJsonContent).jsonObject
|
||||
val packageJsonUpdate = JsonObject(
|
||||
packageJson + ("version" to JsonPrimitive(projectVersion))
|
||||
)
|
||||
val packageJsonContentUpdated =
|
||||
jsonFormatter
|
||||
.encodeToString(packageJsonUpdate)
|
||||
.suffixIfNot("\n")
|
||||
packageJsonFile.asFile.writer().useToRun {
|
||||
write(packageJsonContentUpdated)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tasks.assemble { dependsOn(updatePackageJsonVersion) }
|
||||
|
||||
|
||||
val dataModelTs: Configuration by configurations.creating {
|
||||
asConsumer()
|
||||
typescriptAttributes(objects)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue