Have your backend declare the data types (DTOs) for its API, and use em in the front end. Great when working with Angular or other TypeScript frameworks.
This project is a wrapper around the ts-generator project
build.kotlin.kts
plugins {
id("se.jensim.kt2ts") version "$pluginVersion"
}
kt2ts {
// Repeatable block for linking outputfile to a set of annotations
output {
outputFile = file("$buildDir/ts/kt2ts.d.ts")
annotations = listOf("com.example.ToTypescript")
}
classFilesSources {
// Two ways of setting classes dir, if both are set, both are jointly used
// One has to be provided (for task input resolution to work properly, I made it mandatory)
compileTasks = listOf(tasks.compileKotlin, tasks.compileJava)
classesDirs = files("$buildDir/classes/kotlin/main")
}
}
// Shorthand versions - with default values
kt2ts {
annotation = "com.example.ToTypescript"
classFilesSources.compileTasks = listOf(tasks.compileKotlin, tasks.compileJava)
}
kt2ts {
annotations = listOf("com.example.ToTypescript")
classFilesSources.compileTasks = listOf(tasks.compileKotlin, tasks.compileJava)
}
Your custom annotation and API data classes
package com.example
annotation class ToTypescript
@ToTypescript
data class OneDataType(val types: List<ThreeDataType>, val e: FouthEnum)
data class TwoDataType(val name: String)
data class ThreeDataType(val name: String)
enum class FouthEnum {
FOUR
}
Dependency | License |
---|---|
kt2ts (this) | |
ts-generator | |
reflections | |
javassist (transitive) | |
guava (transitive) |
Because we need something like kt2js https://youtrack.jetbrains.com/issue/KT-16604
We use jacoco for testcoverage of the plugin project, on top of that we build and test the example project that uses the plugin when building master and tagging releases in TravisCI. All plugin publishings to gradle plugin protal are made in trvisCI after a full build & test has been successful in both the plugin and the example project.