diff options
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) + } + ) +} |