Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gradle plugin #6

Open
GuiSim opened this issue Apr 20, 2018 · 7 comments
Open

Gradle plugin #6

GuiSim opened this issue Apr 20, 2018 · 7 comments

Comments

@GuiSim
Copy link

GuiSim commented Apr 20, 2018

This is a very cool project. However, wouldn't it make more sense to run this as part of a Gradle plugin, during the build process, and not as a part of the application's code itself?

I see this as something similar to the kotlin2js plugin.

@ntrrgc
Copy link
Owner

ntrrgc commented Apr 20, 2018

You can create a gradle task if it makes sense for you. Hopefully there is no inconvenience, it's just instantiating a class, calling a method and writing the results to a file, all of which vary a lot depending on your project.

@GuiSim
Copy link
Author

GuiSim commented Apr 27, 2018

I'm really not familiar on how to do this but I'll give it a try and report back here. I suspect that this is a common usage scenario, especially when combined with Kotlin Multiplatform projects

@alexvas
Copy link

alexvas commented Oct 15, 2018

Hello. Here is the Gradle plugin:
https://plugins.gradle.org/plugin/kotlin2ts.kt2ts

@forresthopkinsa
Copy link

@alexvas doesn't work

@alexvas
Copy link

alexvas commented Feb 12, 2019

@forresthopkinsa may you provide a sample that doesn't work?

@forresthopkinsa
Copy link

I ended up just implementing it myself, it was much easier to do.

TypeDefGenerator.kt:

package com.forresthopkinsa.braze.model

import me.ntrrgc.tsGenerator.TypeScriptGenerator

fun main() {
    val classes = setOf(
        RestController.Constants::class,
        JavaVersion::class,
    )
    val ignored = setOf(
        Element::class,
        SimpleElement::class,
        Data::class
    )
    val definitions = TypeScriptGenerator(rootClasses = classes, ignoreSuperclasses = ignored).definitionsText
    println(definitions)
}

build.gradle.kts:

repositories {
    ...
    maven { url = uri("https://jitpack.io") }
}

dependencies {
    ...
    compile("com.github.ntrrgc", "ts-generator", "1.1.1")
}

val generateDefinitions by tasks.creating(JavaExec::class) {
    classpath = sourceSets["main"].runtimeClasspath
    main = "com.forresthopkinsa.braze.model.TypeDefGeneratorKt"
    standardOutput = File(buildDir, "kotlin-model.d.ts").outputStream()
}

val copyDefinitions by tasks.creating(Copy::class) {
    from(File(buildDir, "kotlin-model.d.ts"))
    destinationDir = File(projectDir, "src/frontend/src")
}

@ayedo
Copy link

ayedo commented Nov 9, 2019

I've create a Gradle plugin for ts-generator:

ktsgenerator

Let me know what you think. If you like it, I'd appreciate a ⭐️ :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants