summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlihaoyi <haoyi.sg@gmail.com>2013-10-28 00:48:21 -0700
committerlihaoyi <haoyi.sg@gmail.com>2013-10-28 00:48:21 -0700
commit14c889e632716a1e86c055e2c396179d6d3426df (patch)
tree6e034d7e61d0aadc734a7b1d597fb5ab61ea758c
parent680216d364b760e0f41c25c4f69fc061150a0341 (diff)
downloadworkbench-14c889e632716a1e86c055e2c396179d6d3426df.tar.gz
workbench-14c889e632716a1e86c055e2c396179d6d3426df.tar.bz2
workbench-14c889e632716a1e86c055e2c396179d6d3426df.zip
stuff works
-rw-r--r--plugin/build.sbt6
-rw-r--r--plugin/src/main/scala/scala/js/resource/Plugin.scala17
-rw-r--r--project/Build.scala10
-rw-r--r--project/plugins.sbt1
-rw-r--r--runtime/build.sbt1
-rw-r--r--runtime/project/Build.scala11
-rw-r--r--runtime/project/build.properties1
-rw-r--r--runtime/project/build.sbt5
-rw-r--r--runtime/project/plugins.sbt1
-rw-r--r--runtime/src/main/scala/scala/js/Resource.scala (renamed from runtime/src/main/scala/scala/js/Resources.scala)3
10 files changed, 31 insertions, 25 deletions
diff --git a/plugin/build.sbt b/plugin/build.sbt
index 7c0db51..72dc3e2 100644
--- a/plugin/build.sbt
+++ b/plugin/build.sbt
@@ -1 +1,5 @@
-sbtPlugin := true \ No newline at end of file
+sbtPlugin := true
+
+addSbtPlugin("ch.epfl.lamp" % "scalajs-sbt-plugin" % "0.1-SNAPSHOT")
+
+libraryDependencies += "commons-codec" % "commons-codec" % "1.8"
diff --git a/plugin/src/main/scala/scala/js/resource/Plugin.scala b/plugin/src/main/scala/scala/js/resource/Plugin.scala
index cfa68af..69da094 100644
--- a/plugin/src/main/scala/scala/js/resource/Plugin.scala
+++ b/plugin/src/main/scala/scala/js/resource/Plugin.scala
@@ -2,29 +2,34 @@ package scala.js.resource
import sbt._
import Keys._
+import ch.epfl.lamp.sbtscalajs.ScalaJSPlugin.ScalaJSKeys._
+import org.apache.commons.codec.binary.Base64
+
object Plugin extends sbt.Plugin {
- val myTask = taskKey[Set[File]]("prepares resources")
+
val resourceSettings = Seq(
watchSources := {
watchSources.value ++ (resources in Compile).value
},
+ packageJS := {
- myTask := {
val fileData = for{
resourceRoot <- (resources in Compile).value
(file, path) <- Path.allSubpaths(resourceRoot)
} yield {
- path -> new sun.misc.BASE64Encoder().encode(IO.readBytes(file)).replace("\n", "").replace("\r", "")
+ val b64 = Base64.encodeBase64String(IO.readBytes(file))
+ path -> b64
}
val bundle = crossTarget.value / "resources.js"
- val fileLines = for((path, data) <- fileData) yield { " \"" + path + "\": ScalaJS.Resource(\"" + data + "\")" }
-
+ val fileLines = for((path, data) <- fileData) yield {
+ " \"" + path + "\": ScalaJS.modules.scala_js_Resource().create(\"" + data + "\")"
+ }
IO.write(bundle, "\nScalaJS.resources = {\n" + fileLines.mkString(",\n") + "\n}" )
- Set(bundle)
+ (packageJS in Compile).value :+ bundle
}
)
}
diff --git a/project/Build.scala b/project/Build.scala
new file mode 100644
index 0000000..50dda40
--- /dev/null
+++ b/project/Build.scala
@@ -0,0 +1,10 @@
+import sbt._
+
+object Build extends sbt.Build {
+ import sbt._
+
+ lazy val runtime = Project("runtime", file("runtime"))
+ lazy val plugin = Project("plugin", file("plugin"))
+
+
+} \ No newline at end of file
diff --git a/project/plugins.sbt b/project/plugins.sbt
new file mode 100644
index 0000000..d872618
--- /dev/null
+++ b/project/plugins.sbt
@@ -0,0 +1 @@
+addSbtPlugin("ch.epfl.lamp" % "scalajs-sbt-plugin" % "0.1-SNAPSHOT") \ No newline at end of file
diff --git a/runtime/build.sbt b/runtime/build.sbt
new file mode 100644
index 0000000..fa2803f
--- /dev/null
+++ b/runtime/build.sbt
@@ -0,0 +1 @@
+scalaJSSettings \ No newline at end of file
diff --git a/runtime/project/Build.scala b/runtime/project/Build.scala
deleted file mode 100644
index b7d4ecc..0000000
--- a/runtime/project/Build.scala
+++ /dev/null
@@ -1,11 +0,0 @@
-import sbt._
-import Keys._
-import ch.epfl.lamp.sbtscalajs.ScalaJSPlugin._
-import ScalaJSKeys._
-
-object Build extends sbt.Build {
- lazy val resource =
- project.in(file("."))
- .settings(scalaJSSettings: _*)
- .settings(name := "resources")
-} \ No newline at end of file
diff --git a/runtime/project/build.properties b/runtime/project/build.properties
deleted file mode 100644
index 1ebc8a2..0000000
--- a/runtime/project/build.properties
+++ /dev/null
@@ -1 +0,0 @@
- sbt.version=0.13.0
diff --git a/runtime/project/build.sbt b/runtime/project/build.sbt
deleted file mode 100644
index 3407493..0000000
--- a/runtime/project/build.sbt
+++ /dev/null
@@ -1,5 +0,0 @@
-addSbtPlugin("ch.epfl.lamp" % "scalajs-sbt-plugin" % "0.1-SNAPSHOT")
-
-addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.5.1")
-
-
diff --git a/runtime/project/plugins.sbt b/runtime/project/plugins.sbt
new file mode 100644
index 0000000..d872618
--- /dev/null
+++ b/runtime/project/plugins.sbt
@@ -0,0 +1 @@
+addSbtPlugin("ch.epfl.lamp" % "scalajs-sbt-plugin" % "0.1-SNAPSHOT") \ No newline at end of file
diff --git a/runtime/src/main/scala/scala/js/Resources.scala b/runtime/src/main/scala/scala/js/Resource.scala
index 7bf344c..4cb2aac 100644
--- a/runtime/src/main/scala/scala/js/Resources.scala
+++ b/runtime/src/main/scala/scala/js/Resource.scala
@@ -3,8 +3,9 @@ package scala.js
object Resource {
def apply(path: String) = {
- Dynamic.global.ScalaJS.resources(path)
+ Dynamic.global.ScalaJS.resources.asInstanceOf[js.Dictionary].apply(path)
}
+ def create(value: String) = new Resource(value)
}
class Resource(base64: String){