Skip to content

Commit

Permalink
js-web: Also open web page in browser (linux/mac only)
Browse files Browse the repository at this point in the history
  • Loading branch information
marzipankaiser committed May 28, 2024
1 parent 55f1430 commit d54bcb8
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions effekt/jvm/src/main/scala/effekt/Runner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,15 @@ object JSWebRunner extends Runner[String] {

/**
* Creates an openable `.html` file besides the given `.js` file ([[path]])
* and then returns the absolute path of the created executable.
* and then returns the absolute path of a shell script opening it.
*/
def build(path: String)(using C: Context): String =
import java.nio.file.Path
val out = C.config.outputPath().getAbsolutePath
val jsFilePath = (out / path).unixPath
val jsFileName = jsFilePath.split("/").last
val htmlFilePath = jsFilePath.stripSuffix(s".$extension") + ".html"
val shFilePath = jsFilePath.stripSuffix(s".$extension")
val mainName = "$" + jsFileName.stripSuffix(".js") + ".main"
val htmlContent =
s"""<!DOCTYPE html>
Expand All @@ -166,7 +167,10 @@ object JSWebRunner extends Runner[String] {
|</html>
|""".stripMargin
IO.createFile(htmlFilePath, htmlContent, false)
htmlFilePath
IO.createFile(shFilePath,
s"#!/bin/sh\nxdg-open ${htmlFilePath} || open ${htmlFilePath} || echo \"Cannot open browser\"",
true)
shFilePath
}

trait ChezRunner extends Runner[String] {
Expand Down

0 comments on commit d54bcb8

Please sign in to comment.