Is there a way to have multiple main() methods in ...
# javascript
j
Is there a way to have multiple main() methods in a js project, or do I just need to comment out all but one?
๐Ÿ‘€ 1
b
The latter since unlike jvm main is not declared but picked up by the compiler
You could always have your single main call different localMain functions depending on cli, end or any other boot parameter
j
๐Ÿ‘ thanks
e
a
I was just wondering about this @Jonathan Ellis. In my case for OPENRNDR, and I came up with this approach:
Copy code
// TemplateProgram.kt
fun main() = p1

// p1.kt
val p1 = application { ... }

// p2.kt
val p2 == application { ... }
This way I can have multiple programs in the same project and I only need to change the main method to choose which one runs. It only takes a few seconds to recompile when
./gradlew jsRun -t
is active.
๐Ÿ‘ 1
e
I've ended up creating separate Gradle projects, each depending on the common library. then
:foo:jsRun
:bar:jsRun
etc. work as expected
a
Do you mean subprojects inside the same project?
e
yes
๐Ÿ‘ 1
a
Also nice idea. For small experiments I think I prefer to have all the kt files in the same folder... less clicking around ๐Ÿ™‚ But I'll keep thinking about what's more convenient.
I'm used to having 50 or 100 Kotlin programs in the same project, so what I suggested feels closer to that workflow.
Do you have any examples online @ephemient? Curious to see how it looks like.
e
nothing public except my advent of code stuff which only has a single subproject for execution, sorry
๐Ÿ‘ 1