Skip to content

Instantly share code, notes, and snippets.

@stephanos
Created May 31, 2012 14:24
Show Gist options
  • Select an option

  • Save stephanos/2843716 to your computer and use it in GitHub Desktop.

Select an option

Save stephanos/2843716 to your computer and use it in GitHub Desktop.
nodejs for play assets
object Compiler4CoffeeScript {
import play.core.coffeescript._
import org.mozilla.javascript.JavaScriptException
import play.core.coffeescript.CompilationException
def compile(files: Array[File]): String =
(files.map{
f =>
try {
NodeJs.call(Seq("coffee", "--print", "--bare", f.getAbsolutePath))
} catch {
case e: JavaScriptException =>
throw CompilationException(e.getValue.toString, f, None)
}
}).mkString("\n")
}
object NodeJs {
import scala.sys.process._
import org.mozilla.javascript._
def call(cmd: Seq[String]) = {
// I/O
val stderr = new StringBuffer()
val stdout = new StringBuffer()
val logger = ProcessLogger(
(out: String) => {
stdout append (out + "\n")
},
(err: String) => {
stdout append (err + "\n")
})
// exec
val process = Process(cmd.mkString(" "))
val exit = process ! logger
val out = stdout.toString
if (exit != 0)
throw new JavaScriptException(out)
out
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment