vojtechhabarta / typescript-generator

Generates TypeScript from Java - JSON declarations, REST service client

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support for external classes/dependencies?

sussyGaymer opened this issue · comments

Is there any way to make it export every single class and interface? It would be awesome if I could do that.
At the moment it errors if you try to use it with an externally linked jar.

The plugin works fine with external interfaces, as it uses Reflection on the classpath, which should contain them. Show us your Maven config.

I am using ForgeGradle (for an older version of Minecraft) so it might be a problem with it's process of setting up the workspace and linking the source jar (the "external dependency"). Here's the build.gradle anyways:

buildscript {
    repositories {
        jcenter()
        maven { url = "https://files.minecraftforge.net/maven" }
    }
    dependencies {
        classpath 'net.minecraftforge.gradle:ForgeGradle:2.3-SNAPSHOT'
        classpath group: 'cz.habarta.typescript-generator', name: 'typescript-generator-gradle-plugin', version: '2.9.456'
    }
}

apply plugin: 'net.minecraftforge.gradle.forge'

version = "0.0.1"
group = "com.sussygaymer.project"
archivesBaseName = "project"

sourceCompatibility = targetCompatibility = '1.8'
compileJava {
    sourceCompatibility = targetCompatibility = '1.8'
}

minecraft {
    version = "1.12.2-14.23.5.2847"
    runDir = "run"
    mappings = "snapshot_20171003"
}

processResources {
    inputs.property "version", project.version
    inputs.property "mcversion", project.minecraft.version

    from(sourceSets.main.resources.srcDirs) {
        include 'mcmod.info'

        expand 'version':project.version, 'mcversion':project.minecraft.version
    }

    from(sourceSets.main.resources.srcDirs) {
        exclude 'mcmod.info'
    }
}

apply plugin: 'cz.habarta.typescript-generator'

generateTypeScript {
    jsonLibrary = 'jackson2'
    classPatterns = [
        'com.sussygaymer.project.**'
    ]
    outputFile = 'build/typedef.d.ts'
    outputKind = 'global'
}

build.dependsOn generateTypeScript

I get the following output when building (presumably it's trying to load the class but doesn't find it):

> Task :generateTypeScript FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':generateTypeScript'.
> net/minecraftforge/fml/common/event/FMLInitializationEvent

It finds the class and begins parsing it but it fails when trying to figure out about FMLInitializationEvent.

I assumed it was an issue with how Forge deobfuscates Minecraft, but could the problem be on my end?

I feel like to a certain extent this could be a design issue.

You are trying to serialize something which ultimately isn't supposed to be serializable. The Forge initialization event isn't really something that is supposed to be converted to TypeScript.

Try to decouple your data classes from your logic, that way you are able to serialize exclusively what is inside of the objects.

A pretty dumb example (which might not apply to you), but that showcases the concept nonetheless:

public class SomeDataObject {
  private FMLInitializationEvent event;
  
  public void processEvent() {
     System.out.println("Hello from the event!" + event.toString());
  }

Would be decoupled as such

public class DecoupledObject {
  public void processEvent(FMLInitializationEvent event) {
     System.out.println("Hello from the event!" + event.toString());
  }
}

If you need other help, feel free to reach out on discord at: masecla22#4309