Hi Joffrey! Actually there is a way. This is exactly what I did with some of my pet projects.
The general divide-and-conquer approach worked for me pretyh well.
Here's the list of steps:
1) move some small yet isolated piece of funcionality to Kotlin, annotate all public methods with @JsName, don't use dce at this point
2) use that code in typescript. Don't forget to add kotlin runtime. Also, unforunately, as of now, you'd have to write typescript declarations for that newly exposed Kotlin API on your own.
3) among all pieces of code that use that new API find that ones that are also isolated - that is, are using that piece of code but nothing else, repeat step 1)
4) do this until everything will be translated.
As of the technical part of your question - sure, we can do anything in gradle that can be formalized as a program - if you have any repo I can reach and take a look I can give practical advise.
In general you just need to declare a typescript compilation task and depend on it while building the koltin project.