Skip to content

make more extendable by allowing to plug-in custom emitters? #86

@emmanueltouzery

Description

@emmanueltouzery

A colleague of mine opened #22 some time ago. We didn't fix that issue yet but now we're far enough that it's becoming a bigger hindrance and it's again on our radar.
You mentioned solutions (1), (2) and (3).
I now think only (3) is realistic for us, because besides the ng-grid use-case we also internally developed some filter mechanism where the client-side sends to the server a filter specification. That specification also refers to fields in the DTOs in the same way as ng-grid, and we don't intend to change that (it's a different problem than for ng-grid, because our specification is going over the wire to the server).

Also (2) is interesting, but incomplete, for instance we often have specifications like "field1.field2" (with field2 most of the time belongs to another class than field1).

So the ideal solution would be to generate some TS code which would allow us to type something like:

ClassName.field1.get() => "field1"
ClassName.field1.field2.get() => "field1.field2"

I've looked a bit at the code, and I think it would be possible for us to effectively fork typescript-generator-maven-plugin, and when it calls typescript-generator-core, we would paste-in that definition:

private void generateTypeScript(Input input, Output output, boolean forceExportKeyword, int initialIndentationLevel) {
final Model model = getModelParser().parseModel(input.getSourceTypes());
final TsModel tsModel = getModelCompiler().javaToTypeScript(model);
getEmitter().emit(tsModel, output.getWriter(), output.getName(), output.shouldCloseWriter(), forceExportKeyword, initialIndentationLevel);
}

and use the TsModel to generate the TS code that we want, besides calling typescript-generator-core's generator to generate the TSD as usual (I didn't check yet if enough of the classes from the core are really public, but I think they are).

But I don't like forking typescript-generator-maven-plugin, especially because we would probably put our fork on maven-central. So I'm wondering if there is maybe a way to get to the TsModel already now, and achieve our purpose, or maybe such an extension mechanism could be added?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions