create TypeScriptToLua Gradle task, and some Gradle cleanup / experiments
This commit is contained in:
parent
d3c7abff95
commit
727836a031
3 changed files with 103 additions and 82 deletions
|
|
@ -0,0 +1,43 @@
|
||||||
|
package dev.adamko.kafkatorio.task
|
||||||
|
|
||||||
|
import com.github.gradle.node.npm.task.NpmTask
|
||||||
|
import org.gradle.api.file.DirectoryProperty
|
||||||
|
import org.gradle.api.plugins.BasePlugin
|
||||||
|
import org.gradle.api.tasks.InputDirectory
|
||||||
|
import org.gradle.api.tasks.OutputFile
|
||||||
|
import org.gradle.api.tasks.PathSensitive
|
||||||
|
import org.gradle.api.tasks.PathSensitivity
|
||||||
|
import org.gradle.api.tasks.SkipWhenEmpty
|
||||||
|
import org.jetbrains.kotlin.util.parseSpaceSeparatedArgs
|
||||||
|
|
||||||
|
abstract class TypescriptToLuaTask : NpmTask() {
|
||||||
|
|
||||||
|
@get:InputDirectory
|
||||||
|
@get:SkipWhenEmpty
|
||||||
|
@get:PathSensitive(PathSensitivity.RELATIVE)
|
||||||
|
abstract val sourceFiles: DirectoryProperty
|
||||||
|
|
||||||
|
@get:OutputFile
|
||||||
|
abstract val outputDirectory: DirectoryProperty
|
||||||
|
|
||||||
|
|
||||||
|
init {
|
||||||
|
super.setGroup(BasePlugin.BUILD_GROUP)
|
||||||
|
super.setDescription("Convert Typescript To Lua")
|
||||||
|
super.execOverrides { standardOutput = System.out }
|
||||||
|
super.npmCommand.set(listOf("run", "build"))
|
||||||
|
super.args.set(parseSpaceSeparatedArgs("-- --outDir $temporaryDir"))
|
||||||
|
super.ignoreExitValue.set(false)
|
||||||
|
super.doFirst("cleanTemporaryDir") {
|
||||||
|
project.delete(temporaryDir)
|
||||||
|
project.mkdir(temporaryDir)
|
||||||
|
}
|
||||||
|
super.doLast("syncTstlOutput") {
|
||||||
|
project.sync {
|
||||||
|
from(temporaryDir)
|
||||||
|
into(outputDirectory)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,12 +1,10 @@
|
||||||
import com.github.gradle.node.npm.task.NpmTask
|
|
||||||
import dev.adamko.kafkatorio.gradle.asConsumer
|
import dev.adamko.kafkatorio.gradle.asConsumer
|
||||||
import dev.adamko.kafkatorio.gradle.asProvider
|
import dev.adamko.kafkatorio.gradle.asProvider
|
||||||
import dev.adamko.kafkatorio.gradle.factorioModAttributes
|
import dev.adamko.kafkatorio.gradle.factorioModAttributes
|
||||||
import dev.adamko.kafkatorio.gradle.typescriptAttributes
|
import dev.adamko.kafkatorio.gradle.typescriptAttributes
|
||||||
import groovy.json.JsonOutput
|
import dev.adamko.kafkatorio.task.TypescriptToLuaTask
|
||||||
import net.swiftzer.semver.SemVer
|
import net.swiftzer.semver.SemVer
|
||||||
import org.apache.tools.ant.filters.ReplaceTokens
|
import org.apache.tools.ant.filters.ReplaceTokens
|
||||||
import org.jetbrains.kotlin.util.parseSpaceSeparatedArgs
|
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
dev.adamko.kafkatorio.lang.node
|
dev.adamko.kafkatorio.lang.node
|
||||||
|
|
@ -47,6 +45,7 @@ node {
|
||||||
}
|
}
|
||||||
|
|
||||||
val typescriptEventsSchema: Configuration by configurations.creating {
|
val typescriptEventsSchema: Configuration by configurations.creating {
|
||||||
|
description = "Fetch the TypeScript schema from the event-schema subproject"
|
||||||
asConsumer()
|
asConsumer()
|
||||||
typescriptAttributes(objects)
|
typescriptAttributes(objects)
|
||||||
}
|
}
|
||||||
|
|
@ -55,39 +54,11 @@ dependencies {
|
||||||
typescriptEventsSchema(projects.modules.eventsSchema)
|
typescriptEventsSchema(projects.modules.eventsSchema)
|
||||||
}
|
}
|
||||||
|
|
||||||
val typescriptToLua by tasks.registering(NpmTask::class) {
|
val typescriptToLua by tasks.registering(TypescriptToLuaTask::class) {
|
||||||
description = "Convert Typescript To Lua"
|
|
||||||
group = project.name
|
|
||||||
|
|
||||||
dependsOn(tasks.npmInstall, installEventsTsSchema, tasks.updatePackageJson)
|
dependsOn(tasks.npmInstall, installEventsTsSchema, tasks.updatePackageJson)
|
||||||
|
|
||||||
execOverrides { standardOutput = System.out }
|
sourceFiles.set(tsSrcDir)
|
||||||
|
outputDirectory.set(layout.buildDirectory.dir("typescriptToLua"))
|
||||||
npmCommand.set(listOf("run", "build"))
|
|
||||||
|
|
||||||
inputs.dir(tsSrcDir)
|
|
||||||
.skipWhenEmpty()
|
|
||||||
.withPropertyName("sourceFiles")
|
|
||||||
.withPathSensitivity(PathSensitivity.RELATIVE)
|
|
||||||
|
|
||||||
args.set(parseSpaceSeparatedArgs("-- --outDir $temporaryDir"))
|
|
||||||
val outputDir = layout.buildDirectory.dir("typescriptToLua")
|
|
||||||
outputs.dir(outputDir)
|
|
||||||
.withPropertyName("outputDir")
|
|
||||||
|
|
||||||
ignoreExitValue.set(false)
|
|
||||||
|
|
||||||
doFirst("clean") {
|
|
||||||
delete(temporaryDir)
|
|
||||||
mkdir(temporaryDir)
|
|
||||||
}
|
|
||||||
|
|
||||||
doLast("syncTstlOutput") {
|
|
||||||
sync {
|
|
||||||
from(temporaryDir)
|
|
||||||
into(outputDir)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val installEventsTsSchema by tasks.registering(Sync::class) {
|
val installEventsTsSchema by tasks.registering(Sync::class) {
|
||||||
|
|
@ -133,7 +104,7 @@ distributions {
|
||||||
include("**/**")
|
include("**/**")
|
||||||
}
|
}
|
||||||
from(licenseFile)
|
from(licenseFile)
|
||||||
from(typescriptToLua.map { it.outputs })
|
from(typescriptToLua.map { it.outputDirectory })
|
||||||
filesNotMatching("**/*.png") {
|
filesNotMatching("**/*.png") {
|
||||||
filter<ReplaceTokens>("tokens" to projectTokens)
|
filter<ReplaceTokens>("tokens" to projectTokens)
|
||||||
}
|
}
|
||||||
|
|
@ -149,34 +120,34 @@ distributions {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val downloadFactorioApiDocs by tasks.registering {
|
//val downloadFactorioApiDocs by tasks.registering {
|
||||||
group = project.name
|
// group = project.name
|
||||||
|
//
|
||||||
val target = uri("https://lua-api.factorio.com/latest/runtime-api.json")
|
// val target = uri("https://lua-api.factorio.com/latest/runtime-api.json")
|
||||||
val apiFilename = File(target.path).name
|
// val apiFilename = File(target.path).name
|
||||||
val downloadedFile = file("$temporaryDir/$apiFilename")
|
// val downloadedFile = file("$temporaryDir/$apiFilename")
|
||||||
|
//
|
||||||
val apiFile = layout.buildDirectory.file(apiFilename)
|
// val apiFile = layout.buildDirectory.file(apiFilename)
|
||||||
outputs.file(apiFile)
|
// outputs.file(apiFile)
|
||||||
|
//
|
||||||
doLast {
|
// doLast {
|
||||||
|
//
|
||||||
ant.invokeMethod(
|
// ant.invokeMethod(
|
||||||
"get", mapOf(
|
// "get", mapOf(
|
||||||
"src" to target,
|
// "src" to target,
|
||||||
"dest" to downloadedFile,
|
// "dest" to downloadedFile,
|
||||||
"verbose" to true,
|
// "verbose" to true,
|
||||||
)
|
// )
|
||||||
)
|
// )
|
||||||
|
//
|
||||||
val json = downloadedFile.readText()
|
// val json = downloadedFile.readText()
|
||||||
val prettyJson = JsonOutput.prettyPrint(json)
|
// val prettyJson = JsonOutput.prettyPrint(json)
|
||||||
|
//
|
||||||
apiFile.get().asFile.writeText(prettyJson)
|
// apiFile.get().asFile.writeText(prettyJson)
|
||||||
|
//
|
||||||
logger.lifecycle("Downloaded Factorio API json: $apiFile")
|
// logger.lifecycle("Downloaded Factorio API json: $apiFile")
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
|
|
||||||
val factorioModProvider by configurations.registering {
|
val factorioModProvider by configurations.registering {
|
||||||
asProvider()
|
asProvider()
|
||||||
|
|
@ -191,27 +162,34 @@ tasks.updatePackageJson {
|
||||||
|
|
||||||
tasks.assemble { dependsOn(installEventsTsSchema, tasks.updatePackageJson) }
|
tasks.assemble { dependsOn(installEventsTsSchema, tasks.updatePackageJson) }
|
||||||
|
|
||||||
//
|
|
||||||
//idea {
|
// trying to get Gradle+idea to recognise the ts-src...
|
||||||
// // this doesn't work - no source sets?
|
|
||||||
// module {
|
//val typescriptSrcSet = project.objects.sourceDirectorySet("typescript", "TypeScript").apply {
|
||||||
// sourceDirs.add(mkdir(layout.projectDirectory.dir("src/main/typescript").asFile))
|
// srcDirs(tsSrcDir)
|
||||||
// excludeDirs.add(mkdir(layout.projectDirectory.dir("src/main/typescript/node_modules").asFile))
|
// compiledBy(typescriptToLua, TypescriptToLuaTask::outputDirectory)
|
||||||
// resourceDirs.add(mkdir(layout.projectDirectory.dir("src/main/resources").asFile))
|
//// destinationDirectory.set(layout.buildDirectory.dir("typescriptToLua"))
|
||||||
// resourceDirs.add(mkdir(layout.projectDirectory.dir("infra").asFile))
|
|
||||||
// excludeDirs.add(mkdir(layout.projectDirectory.dir("infra/factorio-server").asFile))
|
|
||||||
// }
|
|
||||||
//}
|
//}
|
||||||
//
|
//
|
||||||
//val typescriptSrcSet =
|
//val tsSrcConfiguration by configurations.registering {
|
||||||
// project.objects.sourceDirectorySet("typescript", "typescript").apply {
|
// asProvider()
|
||||||
// srcDir(layout.projectDirectory.dir("src/main/typescript"))
|
// outgoing.artifact(tsSrcDir)
|
||||||
|
//}
|
||||||
//
|
//
|
||||||
// destinationDirectory.set(modBuildDir.dir("typescriptToLua").asFile)
|
//idea {
|
||||||
// compiledBy(tstlTask) {
|
// module {
|
||||||
//
|
// // Not using += due to https://github.com/gradle/gradle/issues/8749
|
||||||
// project.objects.directoryProperty().apply {
|
// sourceDirs = sourceDirs + typescriptSrcSet.sourceDirectories
|
||||||
// set(modBuildDir.dir("typescriptToLua"))
|
// resourceDirs.add(file("src/main/resources"))
|
||||||
|
// excludeDirs.add(layout.projectDirectory.dir("src/main/typescript/node_modules").asFile)
|
||||||
|
// scopes.compute("MAIN") { _: String, scope: MutableMap<String, MutableCollection<Configuration>>? ->
|
||||||
|
// val s = (scope ?: mutableMapOf())
|
||||||
|
// s.compute("plus") { _, conf ->
|
||||||
|
// val c = conf ?: mutableListOf()
|
||||||
|
// c.add(tsSrcConfiguration.get())
|
||||||
|
// c
|
||||||
// }
|
// }
|
||||||
|
// s
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
//}
|
||||||
|
|
|
||||||
|
|
@ -96,7 +96,7 @@ kotlin {
|
||||||
|
|
||||||
|
|
||||||
val generateTypescript by tasks.registering(JavaExec::class) {
|
val generateTypescript by tasks.registering(JavaExec::class) {
|
||||||
group = project.name
|
group = "kt2ts"
|
||||||
|
|
||||||
val jvmJar by tasks.getting(Jar::class)
|
val jvmJar by tasks.getting(Jar::class)
|
||||||
val main by kotlin.jvm().compilations.getting
|
val main by kotlin.jvm().compilations.getting
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue