diff options
author | lihaoyi <haoyi.sg@gmail.com> | 2013-10-27 23:45:09 -0700 |
---|---|---|
committer | lihaoyi <haoyi.sg@gmail.com> | 2013-10-27 23:45:09 -0700 |
commit | 680216d364b760e0f41c25c4f69fc061150a0341 (patch) | |
tree | 77f90f75097fb0297c4a00ce0dd65ffe3a84f7a2 /plugin | |
download | workbench-680216d364b760e0f41c25c4f69fc061150a0341.tar.gz workbench-680216d364b760e0f41c25c4f69fc061150a0341.tar.bz2 workbench-680216d364b760e0f41c25c4f69fc061150a0341.zip |
first commit
Diffstat (limited to 'plugin')
-rw-r--r-- | plugin/build.sbt | 1 | ||||
-rw-r--r-- | plugin/src/main/scala/scala/js/resource/Plugin.scala | 30 |
2 files changed, 31 insertions, 0 deletions
diff --git a/plugin/build.sbt b/plugin/build.sbt new file mode 100644 index 0000000..7c0db51 --- /dev/null +++ b/plugin/build.sbt @@ -0,0 +1 @@ +sbtPlugin := true
\ No newline at end of file diff --git a/plugin/src/main/scala/scala/js/resource/Plugin.scala b/plugin/src/main/scala/scala/js/resource/Plugin.scala new file mode 100644 index 0000000..cfa68af --- /dev/null +++ b/plugin/src/main/scala/scala/js/resource/Plugin.scala @@ -0,0 +1,30 @@ +package scala.js.resource + +import sbt._ +import Keys._ + +object Plugin extends sbt.Plugin { + val myTask = taskKey[Set[File]]("prepares resources") + val resourceSettings = Seq( + watchSources := { + watchSources.value ++ (resources in Compile).value + }, + + 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 bundle = crossTarget.value / "resources.js" + val fileLines = for((path, data) <- fileData) yield { " \"" + path + "\": ScalaJS.Resource(\"" + data + "\")" } + + + IO.write(bundle, "\nScalaJS.resources = {\n" + fileLines.mkString(",\n") + "\n}" ) + + Set(bundle) + } + ) +} |