Hi, I'm trying Cloudflare workers with Kotlin but ...
# gradle
d
Hi, I'm trying Cloudflare workers with Kotlin but they have a traditional build.gradle that I naturally want to convert to .kts The whole file is https://github.com/cloudflare/kotlin-worker-hello-world/blob/master/build.gradle and it is very basic except one crucial hack that merges a string with a file:
Copy code
/* Kotlin js output assumes window exists, which it won't on Workers. Hack around it */
(new File("$projectDir/index.js")).text = "const window=this; " + file("$projectDir/build/distributions/${rootProject.name}.js").getText()
How do I write this in build.gradle.kts?
Copy code
File("$projectDir/index.js").text
Where .text seem to be some kind of extension to the File object that is not available in Kotlin? PS. I don't know why they use kotlin.target.browser and not target.nodejs but maybe it is to get access to org.w3c.* stuff. Thanks!
e
file.text
=>
file.readText()
file.text = "some"
=>
file.writeText("some")
🤩 2
👆 2
K 2
👍 2
d
Thanks a lot @eskatos, seems obvious in hindsight but I really had googled 🙂
simple smile 2
g
It actually looks as wrong config, not clear why they do target browser,
kotlin.target.browser
it probably should be
kotlin.target.nodejs
) So it will not require any hacks
If you have some working example, I would instead try to fix it
d
I will give it a try later!