backing up before finally deciding on how to sync Kotlin and Typescript data model
This commit is contained in:
parent
7dd7baef34
commit
b3af697636
23 changed files with 679 additions and 97 deletions
|
|
@ -1,8 +1,27 @@
|
|||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
|
||||
plugins {
|
||||
idea
|
||||
`kotlin-dsl`
|
||||
kotlin("jvm") version "1.5.31"
|
||||
`java-gradle-plugin`
|
||||
}
|
||||
|
||||
gradlePlugin {
|
||||
plugins {
|
||||
create("tstl") {
|
||||
id = "dev.adamko.tstl"
|
||||
description =
|
||||
"Gradle plugin for TypescriptToLua. Requires plugin `com.github.node-gradle.node`."
|
||||
implementationClass = "dev.adamko.gradle.tstl.TstlPlugin"
|
||||
}
|
||||
create("json-kotlin-schema-gen") {
|
||||
id = "dev.adamko.json-kotlin-schema-gen"
|
||||
description =
|
||||
"Gradle plugin for 'json-kotlin-schema-codegen' - Code generation for JSON Schema (Draft 07) https://github.com/pwall567/json-kotlin-schema-codegen"
|
||||
implementationClass = "dev.adamko.gradle.jsonkotlinschemagen.JsonKotlinSchemaGenPlugin"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
|
@ -21,18 +40,43 @@ dependencies {
|
|||
|
||||
implementation("com.github.node-gradle:gradle-node-plugin:3.1.1")
|
||||
|
||||
implementation("net.pwall.json:json-kotlin-schema-codegen:0.53")
|
||||
}
|
||||
|
||||
val projectJvmTarget = "11"
|
||||
|
||||
tasks.withType<KotlinCompile>().configureEach {
|
||||
|
||||
kotlinOptions {
|
||||
jvmTarget = "11"
|
||||
jvmTarget = projectJvmTarget
|
||||
apiVersion = "1.5"
|
||||
languageVersion = "1.5"
|
||||
}
|
||||
|
||||
kotlinOptions.freeCompilerArgs += listOf(
|
||||
"-Xopt-in=kotlin.OptIn",
|
||||
"-Xopt-in=kotlin.RequiresOptIn",
|
||||
"-Xopt-in=kotlin.ExperimentalStdlibApi",
|
||||
"-Xopt-in=kotlin.time.ExperimentalTime",
|
||||
"-Xopt-in=kotlinx.coroutines.ExperimentalCoroutinesApi",
|
||||
"-Xopt-in=kotlinx.serialization.ExperimentalSerializationApi",
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
kotlin {
|
||||
jvmToolchain {
|
||||
(this as JavaToolchainSpec).languageVersion.set(JavaLanguageVersion.of(projectJvmTarget))
|
||||
}
|
||||
|
||||
kotlinDslPluginOptions {
|
||||
jvmTarget.set(projectJvmTarget)
|
||||
}
|
||||
}
|
||||
|
||||
idea {
|
||||
module {
|
||||
isDownloadSources = true
|
||||
isDownloadJavadoc = true
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ kotlin {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
val kotlinWrappersVersion = "0.0.1-pre.259-kotlin-1.5.31"
|
||||
val kotlinWrappersVersion = "0.0.1-pre.263-kotlin-1.5.31"
|
||||
implementation(
|
||||
project.dependencies.enforcedPlatform(
|
||||
"org.jetbrains.kotlin-wrappers:kotlin-wrappers-bom:${kotlinWrappersVersion}"
|
||||
|
|
@ -48,7 +48,7 @@ val rootPackageJson by rootProject.tasks.getting(RootPackageJsonTask::class)
|
|||
val nodePath: Directory by extra {
|
||||
val file = rootPackageJson.rootPackageJson.parentFile.normalize()
|
||||
logger.lifecycle("Kotlin/JS NODE_PATH: $file")
|
||||
project.layout.dir(provider { file }).get()
|
||||
project.layout.dir(project.provider { file }).get()
|
||||
}
|
||||
|
||||
val nodeModulesDir: Directory by extra {
|
||||
|
|
@ -56,14 +56,3 @@ val nodeModulesDir: Directory by extra {
|
|||
logger.lifecycle("Kotlin/JS NODE_MODULES: $file")
|
||||
file
|
||||
}
|
||||
|
||||
node {
|
||||
download.set(true)
|
||||
version.set("14.18.0")
|
||||
|
||||
distBaseUrl.set(null as String?) // set by dependencyResolutionManagement
|
||||
|
||||
// nodeProjectDir.set(nodePath)
|
||||
// nodeProjectDir.set(packageJson.packageJson.parentFile.normalize())
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -43,11 +43,20 @@ dependencies {
|
|||
}
|
||||
|
||||
tasks.withType<KotlinCompile>().configureEach {
|
||||
|
||||
kotlinOptions {
|
||||
jvmTarget = "11"
|
||||
apiVersion = "1.5"
|
||||
languageVersion = "1.5"
|
||||
}
|
||||
|
||||
kotlinOptions.freeCompilerArgs += listOf(
|
||||
"-Xopt-in=kotlin.OptIn",
|
||||
"-Xopt-in=kotlin.RequiresOptIn",
|
||||
"-Xopt-in=kotlin.ExperimentalStdlibApi",
|
||||
"-Xopt-in=kotlin.time.ExperimentalTime",
|
||||
"-Xopt-in=kotlinx.coroutines.ExperimentalCoroutinesApi",
|
||||
"-Xopt-in=kotlinx.serialization.ExperimentalSerializationApi",
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,22 @@
|
|||
package dev.adamko.factoriowebmap.archetype
|
||||
|
||||
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension
|
||||
|
||||
|
||||
plugins {
|
||||
id("dev.adamko.factoriowebmap.archetype.base")
|
||||
id("dev.adamko.factoriowebmap.archetype.node")
|
||||
kotlin("multiplatform")
|
||||
}
|
||||
|
||||
|
||||
afterEvaluate {
|
||||
|
||||
rootProject.extensions.configure<NodeJsRootExtension> {
|
||||
val projectNodeInstallDir = file("$rootDir/.gradle").resolve("nodejs")
|
||||
if (installationDir != projectNodeInstallDir) {
|
||||
installationDir = projectNodeInstallDir
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -2,7 +2,10 @@ package dev.adamko.factoriowebmap.archetype
|
|||
|
||||
import org.gradle.kotlin.dsl.kotlin
|
||||
import com.github.gradle.node.npm.task.NpmTask
|
||||
import com.github.gradle.node.npm.task.NpxTask
|
||||
import com.github.gradle.node.task.NodeTask
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinMultiplatformPlugin
|
||||
import org.jetbrains.kotlin.gradle.targets.js.KotlinJsPlugin
|
||||
import org.jetbrains.kotlin.gradle.targets.js.dukat.DtsResolver
|
||||
import org.jetbrains.kotlin.gradle.targets.js.npm.tasks.RootPackageJsonTask
|
||||
import org.jetbrains.kotlin.gradle.targets.js.npm.tasks.KotlinPackageJsonTask
|
||||
|
|
@ -21,3 +24,6 @@ node {
|
|||
distBaseUrl.set(null as String?) // set by dependencyResolutionManagement
|
||||
}
|
||||
|
||||
project.plugins.withType<KotlinJsPlugin>()
|
||||
project.plugins.withType<KotlinMultiplatformPlugin>()
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,12 @@
|
|||
package dev.adamko.gradle
|
||||
|
||||
import org.gradle.kotlin.dsl.`component-model-base`
|
||||
import org.gradle.kotlin.dsl.kotlin
|
||||
|
||||
|
||||
plugins {
|
||||
base
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
package dev.adamko.gradle.tstl
|
||||
|
||||
import com.github.gradle.node.NodePlugin
|
||||
import dev.adamko.gradle.tstl.tasks.TypescriptToLuaTask
|
||||
import org.gradle.api.Plugin
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.plugins.BasePlugin
|
||||
import org.gradle.kotlin.dsl.withType
|
||||
import org.gradle.language.base.plugins.LifecycleBasePlugin
|
||||
|
||||
|
||||
class TstlPlugin : Plugin<Project> {
|
||||
override fun apply(project: Project) {
|
||||
|
||||
project.plugins.withType<NodePlugin> {
|
||||
}
|
||||
|
||||
project.plugins.withType<BasePlugin> {
|
||||
project.tasks.named(LifecycleBasePlugin.ASSEMBLE_TASK_NAME) {
|
||||
dependsOn(project.tasks.withType<TypescriptToLuaTask>())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
package dev.adamko.gradle.tstl.tasks
|
||||
|
||||
import com.github.gradle.node.npm.task.*
|
||||
import org.gradle.api.file.*
|
||||
import org.gradle.api.provider.*
|
||||
import org.gradle.api.tasks.*
|
||||
import org.jetbrains.kotlin.util.parseSpaceSeparatedArgs
|
||||
import org.gradle.kotlin.dsl.*
|
||||
|
||||
abstract class TypescriptToLuaTask : NpmTask() {
|
||||
|
||||
@get:Internal
|
||||
val intermediateOutputDir: RegularFileProperty = project.objects.fileProperty()
|
||||
.convention { temporaryDir }
|
||||
|
||||
@get:Internal
|
||||
val intermediateOutputCanonicalPath: Provider<String> =
|
||||
intermediateOutputDir.map { it.asFile.canonicalPath }
|
||||
|
||||
@get:Input
|
||||
val identifier: Property<String> = project.objects.property<String>().convention(name)
|
||||
|
||||
@get:Internal
|
||||
val luaOutputDirConvention: Provider<Directory> =
|
||||
project.layout.buildDirectory.map { it.dir("typescriptToLua/${identifier.get()}") }
|
||||
|
||||
@get:OutputDirectory
|
||||
val luaOutputDir: DirectoryProperty = project.objects.directoryProperty()
|
||||
.convention(luaOutputDirConvention)
|
||||
|
||||
init {
|
||||
group = "typescriptToLua"
|
||||
|
||||
execOverrides { standardOutput = System.out }
|
||||
|
||||
super.dependsOn(project.tasks.withType<NpmSetupTask>())
|
||||
ignoreExitValue.set(false)
|
||||
}
|
||||
|
||||
@TaskAction
|
||||
fun convert() {
|
||||
args.set(parseSpaceSeparatedArgs("-- --outDir ${intermediateOutputCanonicalPath.get()}"))
|
||||
|
||||
project.delete(intermediateOutputDir.get())
|
||||
|
||||
super.exec()
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue