diff options
author | Li Haoyi <haoyi.sg@gmail.com> | 2014-05-16 21:32:14 -0700 |
---|---|---|
committer | Li Haoyi <haoyi.sg@gmail.com> | 2014-05-16 21:32:14 -0700 |
commit | b30855868910c86f07b355233a4bd60c6d45118b (patch) | |
tree | 2235f068dec270d4879c5ab16dad1f0a6c52f348 | |
parent | cd23d4b072e6b639d27f265ce3219389903b58a2 (diff) | |
parent | 5d68363ac8f7dfe308e638cb7d1bbb610c67dee0 (diff) | |
download | workbench-b30855868910c86f07b355233a4bd60c6d45118b.tar.gz workbench-b30855868910c86f07b355233a4bd60c6d45118b.tar.bz2 workbench-b30855868910c86f07b355233a4bd60c6d45118b.zip |
Merge pull request #5 from hadesgames/play-integration
Added more settings keys in order to integrate with Play Framework
-rw-r--r-- | Plugin.scala | 46 | ||||
-rw-r--r-- | workbench_template.js | 4 |
2 files changed, 36 insertions, 14 deletions
diff --git a/Plugin.scala b/Plugin.scala index c7d3bf3..a363b99 100644 --- a/Plugin.scala +++ b/Plugin.scala @@ -25,6 +25,7 @@ object Plugin extends sbt.Plugin with SimpleRoutingApp{ val localUrl = settingKey[(String, Int)]("localUrl") private[this] val routes = settingKey[Unit]("local websocket server") val bootSnippet = settingKey[String]("piece of javascript to make things happen") + val updatedJS = taskKey[List[String]]("Provides the addresses of the JS files that have changed") val pubSub = actor(new Actor{ var waitingActor: Option[ActorRef] = None @@ -61,7 +62,25 @@ object Plugin extends sbt.Plugin with SimpleRoutingApp{ val workbenchSettings = Seq( localUrl := ("localhost", 12345), - + updatedJS := { + var files: List[String] = Nil + ((crossTarget in Compile).value * "*.js").get.foreach { + (x: File) => + streams.value.log.info("workbench: Checking " + x.getName) + FileFunction.cached(streams.value.cacheDirectory / x.getName, FilesInfo.lastModified, FilesInfo.lastModified) { + (f: Set[File]) => + val fsPath = f.head.getAbsolutePath.drop(new File("").getAbsolutePath.length) + files = fsPath :: files + f + }(Set(x)) + } + files + }, + updatedJS <<= (updatedJS, localUrl) map { (paths, localUrl) => + paths.map { path => + s"http://${localUrl._1}:${localUrl._2}$path" + } + }, extraLoggers := { val clientLogger = FullLogger{ new Logger { @@ -80,19 +99,20 @@ object Plugin extends sbt.Plugin with SimpleRoutingApp{ pubSub ! Json.arr("reload") }, updateBrowsers := { - pubSub ! Json.arr("clear") - ((crossTarget in Compile).value * "*.js").get.map{ (x: File) => - streams.value.log.info("workbench: Checking " + x.getName) - FileFunction.cached(streams.value.cacheDirectory / x.getName, FilesInfo.lastModified, FilesInfo.lastModified){ (f: Set[File]) => - streams.value.log.info("workbench: Refreshing " + x.getName) + val changed = updatedJS.value + // There is no point in clearing the browser if no js files have changed. + if (changed.length > 0) { + pubSub ! Json.arr("clear") - pubSub ! Json.arr( - "run", - "/" + f.head.getAbsolutePath.drop(new File("").getAbsolutePath.length), - bootSnippet.value - ) - f - }(Set(x)) + changed.foreach { + path => + streams.value.log.info("workbench: Refreshing " + path) + pubSub ! Json.arr( + "run", + path, + bootSnippet.value + ) + } } }, routes := startServer(localUrl.value._1, localUrl.value._2){ diff --git a/workbench_template.js b/workbench_template.js index 1eacd31..a16e638 100644 --- a/workbench_template.js +++ b/workbench_template.js @@ -42,7 +42,9 @@ if (data[0] == "run"){ var tag = document.createElement("script") var loaded = false - tag.setAttribute("src", "http://<host>:<port>" + data[1]) + + tag.setAttribute("src", data[1]) + var bootSnippet = data[2] if (bootSnippet){ tag.onreadystatechange = tag.onload = function() { |