tasks to move generated ts files to mod project
This commit is contained in:
parent
5ffd5010e4
commit
464d4c28fb
4 changed files with 177 additions and 7 deletions
|
|
@ -74,11 +74,11 @@ project.tasks.withType<ProtobufCompileTask> {
|
||||||
val aggregateTask = project.tasks.register<Sync>("protobufCompileAll") {
|
val aggregateTask = project.tasks.register<Sync>("protobufCompileAll") {
|
||||||
group = Constants.PBG_TASK_GROUP
|
group = Constants.PBG_TASK_GROUP
|
||||||
|
|
||||||
dependsOn(tasks.withType<ProtobufCompileTask>())
|
val pbCompileTasks = tasks.withType<ProtobufCompileTask>()
|
||||||
|
dependsOn(pbCompileTasks)
|
||||||
|
|
||||||
val genSrcDir = project.layout.pbAndGBuildDir.map { it.dir("generated-sources") }
|
val genSrcDir = project.layout.pbAndGBuildDir.map { it.dir("generated-sources") }
|
||||||
|
|
||||||
val pbCompileTasks = tasks.withType<ProtobufCompileTask>()
|
|
||||||
from(pbCompileTasks.map { it.temporaryDir })
|
from(pbCompileTasks.map { it.temporaryDir })
|
||||||
into(genSrcDir)
|
into(genSrcDir)
|
||||||
includeEmptyDirs = false
|
includeEmptyDirs = false
|
||||||
|
|
|
||||||
|
|
@ -88,21 +88,35 @@ val nodeModulesDir: Directory by extra {
|
||||||
}
|
}
|
||||||
|
|
||||||
afterEvaluate {
|
afterEvaluate {
|
||||||
tasks.register<ProtobufCompileTask>("protobufJava") {
|
val protobufJava by tasks.creating(ProtobufCompileTask::class) {
|
||||||
description = "proto2java"
|
description = "proto2java"
|
||||||
protoFile.set(file("$projectDir/src/proto/FactorioServerLogRecord.proto"))
|
protoFile.set(file("$projectDir/src/proto/FactorioServerLogRecord.proto"))
|
||||||
|
|
||||||
cliArgs.add("--java_out=lite:${project.mkdir("$temporaryDir/java").canonicalPath}")
|
cliArgs.add("--java_out=lite:${project.mkdir("$temporaryDir/java").canonicalPath}")
|
||||||
}
|
}
|
||||||
|
val protobufKotlin by tasks.creating(ProtobufCompileTask::class) {
|
||||||
tasks.register<ProtobufCompileTask>("protobufKotlin") {
|
|
||||||
description = "proto2kotlin"
|
description = "proto2kotlin"
|
||||||
protoFile.set(file("$projectDir/src/proto/FactorioServerLogRecord.proto"))
|
protoFile.set(file("$projectDir/src/proto/FactorioServerLogRecord.proto"))
|
||||||
|
|
||||||
cliArgs.add("--kotlin_out=lite:${project.mkdir("$temporaryDir/kotlin").canonicalPath}")
|
cliArgs.add("--kotlin_out=lite:${project.mkdir("$temporaryDir/kotlin").canonicalPath}")
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.register<ProtobufCompileTask>("protobufTypescript") {
|
|
||||||
|
val ktProto by configurations.creating {
|
||||||
|
isCanBeResolved = false
|
||||||
|
isCanBeConsumed = true
|
||||||
|
}
|
||||||
|
|
||||||
|
artifacts {
|
||||||
|
add(ktProto.name, protobufJava.outputDir) {
|
||||||
|
builtBy(protobufJava)
|
||||||
|
}
|
||||||
|
add(ktProto.name, protobufKotlin.outputDir) {
|
||||||
|
builtBy(protobufKotlin)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val protobufTypescript by tasks.creating(ProtobufCompileTask::class) {
|
||||||
description = "proto2typescript"
|
description = "proto2typescript"
|
||||||
|
|
||||||
// linux:
|
// linux:
|
||||||
|
|
@ -126,4 +140,15 @@ afterEvaluate {
|
||||||
|
|
||||||
protoFile.set(file("$projectDir/src/proto/FactorioServerLogRecord.proto"))
|
protoFile.set(file("$projectDir/src/proto/FactorioServerLogRecord.proto"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val tsProto by configurations.creating {
|
||||||
|
isCanBeResolved = false
|
||||||
|
isCanBeConsumed = true
|
||||||
|
}
|
||||||
|
artifacts {
|
||||||
|
add(tsProto.name, protobufTypescript.outputDir) {
|
||||||
|
builtBy(protobufTypescript)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import com.github.gradle.node.npm.task.NpmTask
|
import com.github.gradle.node.npm.task.NpmTask
|
||||||
import org.jetbrains.kotlin.util.parseSpaceSeparatedArgs
|
|
||||||
import org.apache.tools.ant.filters.ReplaceTokens
|
import org.apache.tools.ant.filters.ReplaceTokens
|
||||||
|
import org.jetbrains.kotlin.util.parseSpaceSeparatedArgs
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
id("dev.adamko.factoriowebmap.archetype.node")
|
id("dev.adamko.factoriowebmap.archetype.node")
|
||||||
|
|
@ -16,6 +16,66 @@ node {
|
||||||
nodeProjectDir.set(tsSrcDir)
|
nodeProjectDir.set(tsSrcDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val tsProto: Configuration by configurations.creating {
|
||||||
|
isCanBeConsumed = false
|
||||||
|
isCanBeResolved = true
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
tsProto(projects.modules.factorioEventsDataModel.dependencyProject.configurations.getByName("tsProto"))
|
||||||
|
}
|
||||||
|
|
||||||
|
val tsProtoFetch by tasks.creating(Sync::class) {
|
||||||
|
group = project.name
|
||||||
|
|
||||||
|
dependsOn(projects.modules.factorioEventsDataModel.dependencyProject.tasks.named("protobufTypescript"))
|
||||||
|
|
||||||
|
val genSrcDir = projects
|
||||||
|
.modules
|
||||||
|
.factorioEventsDataModel
|
||||||
|
.dependencyProject
|
||||||
|
.layout
|
||||||
|
.buildDirectory
|
||||||
|
.dir("pbAndG/generated-sources/typescript")
|
||||||
|
|
||||||
|
val targetDir = "$projectDir/src/main/typescript/proto"
|
||||||
|
|
||||||
|
inputs.dir(genSrcDir)
|
||||||
|
|
||||||
|
from(genSrcDir)
|
||||||
|
into(targetDir)
|
||||||
|
|
||||||
|
doLast {
|
||||||
|
|
||||||
|
fileTree(targetDir).forEach {
|
||||||
|
var text = it.readText()
|
||||||
|
|
||||||
|
text = text.replace(
|
||||||
|
Regex(
|
||||||
|
"""if \(_m0\.util\.Long !== Long\)\s*\{\s*_m0\.util\.Long = Long as any;\s*_m0\.configure\(\);\s*\}"""
|
||||||
|
),
|
||||||
|
""
|
||||||
|
)
|
||||||
|
|
||||||
|
text = text.replace(
|
||||||
|
Regex("""import Long from "long";"""),
|
||||||
|
""
|
||||||
|
)
|
||||||
|
|
||||||
|
text = text.replace(
|
||||||
|
Regex("""import _m0 from "protobufjs\/minimal";"""),
|
||||||
|
""
|
||||||
|
)
|
||||||
|
|
||||||
|
it.writeText(text)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.assemble { dependsOn(tsProtoFetch) }
|
||||||
|
|
||||||
|
|
||||||
val tstlTask = tasks.register<NpmTask>("typescriptToLua") {
|
val tstlTask = tasks.register<NpmTask>("typescriptToLua") {
|
||||||
description = "Convert Typescript To Lua"
|
description = "Convert Typescript To Lua"
|
||||||
group = projectId
|
group = projectId
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,85 @@
|
||||||
|
/* eslint-disable */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
export interface FactorioServerLogRecord {
|
||||||
|
modVersion: string;
|
||||||
|
tick: number;
|
||||||
|
eventType: string;
|
||||||
|
data?: FactorioLuaObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface FactorioLuaObject {
|
||||||
|
objectName: string;
|
||||||
|
luaControl?: LuaControl | undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** https://lua-api.factorio.com/next/LuaControl.html */
|
||||||
|
export interface LuaControl {
|
||||||
|
isPlayer: boolean;
|
||||||
|
surfaceIndex: number;
|
||||||
|
position?: Position;
|
||||||
|
forceIndex: number;
|
||||||
|
player?: LuaPlayer | undefined;
|
||||||
|
entity?: LuaEntity | undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** https://lua-api.factorio.com/next/LuaPlayer.html */
|
||||||
|
export interface LuaPlayer {
|
||||||
|
/** unique ID */
|
||||||
|
index: number;
|
||||||
|
name: string;
|
||||||
|
data: number[];
|
||||||
|
colour?: Colour;
|
||||||
|
isConnected: boolean;
|
||||||
|
isAdmin: boolean;
|
||||||
|
afkTimeTicks: number;
|
||||||
|
onlineTimeTicks: number;
|
||||||
|
lastOnlineTicks: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** https://lua-api.factorio.com/next/LuaEntity.html */
|
||||||
|
export interface LuaEntity {
|
||||||
|
/** (optional) unique ID */
|
||||||
|
unitNumber?: number | undefined;
|
||||||
|
name: string;
|
||||||
|
type: string;
|
||||||
|
/** https://lua-api.factorio.com/next/defines.html#defines.entity_status */
|
||||||
|
status: string;
|
||||||
|
isActive: boolean;
|
||||||
|
isMoving: boolean;
|
||||||
|
/** (optional) The player connected to this character or nil if none. */
|
||||||
|
playerIndex?: number | undefined;
|
||||||
|
/** (optional) The last player that changed any setting on this entity. */
|
||||||
|
lastUserIndex?: number | undefined;
|
||||||
|
/** (optional) */
|
||||||
|
colour?: Colour;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface LuaSurface {
|
||||||
|
/** unique ID */
|
||||||
|
index: number;
|
||||||
|
name: string;
|
||||||
|
daytime: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface LuaForce {
|
||||||
|
/** unique ID */
|
||||||
|
index: number;
|
||||||
|
forceName: string;
|
||||||
|
playerIds: number[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Position {
|
||||||
|
x: number;
|
||||||
|
y: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Colour {
|
||||||
|
red: number;
|
||||||
|
green: number;
|
||||||
|
blue: number;
|
||||||
|
alpha: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue