Created
May 31, 2012 14:24
-
-
Save stephanos/2843716 to your computer and use it in GitHub Desktop.
nodejs for play assets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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