Hi guys, is there a way to incrementally migrate a...
# javascript
j
Hi guys, is there a way to incrementally migrate a TS code base to Kotlin/JS? A bit of context. I have a Gradle multi-project build which consists of: - a Spring Boot server (in Kotlin) - a React app (in typescript) built using Create React App and the Gradle node plugin on top of it I have recently extracted the API client code from the TS subproject into a Kotlin common (multiplatform) subproject of its own. Now, I'd like to setup a Gradle build for the React app that can depend on the local multiplatform subproject, and that can compile the existing TS files. Is this possible? In the end, the goal is to migrate little by little the whole React app to Kotlin.
u
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.
❤️ 1
j
Hi, thanks for your feedback and for proposing your help! Yes, the steps are approximately what I had in mind for the migration. I was mainly wondering if there is already some Kotlin plugin features allowing to configure the actual build automatically. However, as you said, I believe I'll have to go the route that consists of using the node plugin and manually depend on a Typescript compilation task and declared some .d.ts.
s
@Joffrey is your codebase open source?
j
@Systemkern Yes it is, you can find the project I was talking about on my Github: https://github.com/joffrey-bion/seven-wonders
🤗 1
The branch called
client-module
is the one containing the multiplatform client