summaryrefslogtreecommitdiff
path: root/Plugin.scala
diff options
context:
space:
mode:
authorLi Haoyi <haoyi@dropbox.com>2014-04-01 22:18:29 -0700
committerLi Haoyi <haoyi@dropbox.com>2014-04-01 22:18:29 -0700
commit8bda8e06ef8c5e58fe39a23bead814d0175f5b4c (patch)
tree2426ff8ab53f848a13cd9695e9f8d03fd7badedc /Plugin.scala
parent3ee4f794be2e491f142d2cc8aec0db7a0be32484 (diff)
downloadworkbench-8bda8e06ef8c5e58fe39a23bead814d0175f5b4c.tar.gz
workbench-8bda8e06ef8c5e58fe39a23bead814d0175f5b4c.tar.bz2
workbench-8bda8e06ef8c5e58fe39a23bead814d0175f5b4c.zip
0.1.2
Diffstat (limited to 'Plugin.scala')
-rw-r--r--Plugin.scala17
1 files changed, 9 insertions, 8 deletions
diff --git a/Plugin.scala b/Plugin.scala
index 0d18d2f..c7d3bf3 100644
--- a/Plugin.scala
+++ b/Plugin.scala
@@ -2,7 +2,7 @@ package com.lihaoyi.workbench
import akka.actor.{ActorRef, Actor, ActorSystem}
import scala.concurrent.duration._
-import java.nio.file.{Paths}
+
import play.api.libs.json.Json
import sbt._
import Keys._
@@ -19,6 +19,7 @@ object Plugin extends sbt.Plugin with SimpleRoutingApp{
config = ConfigFactory.load(ActorSystem.getClass.getClassLoader),
classLoader = ActorSystem.getClass.getClassLoader
)
+
val refreshBrowsers = taskKey[Unit]("Sends a message to all connected web pages asking them to refresh the page")
val updateBrowsers = taskKey[Unit]("partially resets some of the stuff in the browser")
val localUrl = settingKey[(String, Int)]("localUrl")
@@ -44,15 +45,16 @@ object Plugin extends sbt.Plugin with SimpleRoutingApp{
// a new actor waiting replaces the old one
waitingActor = Some(a)
case (a: ActorRef, None, msgs) =>
- respond(a, "[" + msgs.mkString(",") + "]")
+
+ respond(a, JsArray(msgs).toString)
queuedMessages = Nil
case (msg: JsArray, None, msgs) =>
queuedMessages = msg :: msgs
case (msg: JsArray, Some(a), Nil) =>
- respond(a, "[" + msg + "]")
+ respond(a, Json.arr(msg).toString)
waitingActor = None
case (Clear, Some(a), Nil) =>
- respond(a, "[]")
+ respond(a, Json.arr().toString)
waitingActor = None
}
})
@@ -83,11 +85,10 @@ object Plugin extends sbt.Plugin with SimpleRoutingApp{
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 cwd = Paths.get(new File("").getAbsolutePath)
- val filePath = Paths.get(f.head.getAbsolutePath)
+
pubSub ! Json.arr(
"run",
- "/" + cwd.relativize(filePath).toString,
+ "/" + f.head.getAbsolutePath.drop(new File("").getAbsolutePath.length),
bootSnippet.value
)
f
@@ -100,7 +101,7 @@ object Plugin extends sbt.Plugin with SimpleRoutingApp{
complete{
IO.readStream(
getClass.getClassLoader
- .getResourceAsStream("workbench_template.ts")
+ .getResourceAsStream("workbench_template.js")
).replace("<host>", localUrl.value._1)
.replace("<port>", localUrl.value._2.toString)
.replace("<bootSnippet>", bootSnippet.value)