Coder Social home page Coder Social logo

lppedd / kt2ts-gradle-plugin Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jensim/kt2ts-gradle-plugin

1.0 2.0 0.0 203 KB

Generate TypeScript from Kotlin (or any jvm language) by annotations

License: Apache License 2.0

Kotlin 97.32% Java 2.68%

kt2ts-gradle-plugin's Introduction

Kotlin to TypeScript gradle-plugin

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

Project Status: Active โ€“ The project has reached a stable, usable state and is being actively developed. License Gradle Plugin Portal Build Status Quality Gate Status Coverage Lines of Code Maintainability Rating

Usage

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
}

Dependencies and license stuff

Dependency License
kt2ts (this) License
ts-generator License
reflections WTFPL
javassist (transitive) License: MPL 2.0
guava (transitive) License

Why?

Because we need something like kt2js https://youtrack.jetbrains.com/issue/KT-16604

Tests & CI

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.

kt2ts-gradle-plugin's People

Contributors

jensim avatar

Stargazers

 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.