From 850863823caf3c33e7f020d43877143ce8de00f5 Mon Sep 17 00:00:00 2001 From: Jakob Odersky Date: Mon, 3 Nov 2014 12:01:33 +0100 Subject: refactor build --- project/Build.scala | 13 +++++------- project/Dependencies.scala | 5 +---- project/plugins.sbt | 2 +- project/util.scala | 53 +++++++++++++++++++++++++--------------------- 4 files changed, 36 insertions(+), 37 deletions(-) (limited to 'project') diff --git a/project/Build.scala b/project/Build.scala index 678c8d2..fe249df 100644 --- a/project/Build.scala +++ b/project/Build.scala @@ -11,10 +11,8 @@ import Dependencies._ object ApplicationBuild extends Build { val common = Seq( - scalaVersion := "2.11.2", - scalacOptions ++= Seq("-feature"), - unmanagedSourceDirectories in Compile += (baseDirectory in ThisBuild).value / "vfd-shared" / "src" / "main" / "scala", - unmanagedResourceDirectories in Compile += (baseDirectory in ThisBuild).value / "vfd-shared" / "src" / "main" / "resources" + scalaVersion := "2.11.4", + scalacOptions ++= Seq("-feature", "-deprecation") ) lazy val root = Project("root", file(".")).aggregate( @@ -40,12 +38,12 @@ object ApplicationBuild extends Build { enablePlugins(PlayScala) settings(common: _*) settings( + relativeSourceMaps := true, resolvers += Resolver.url("scala-js-releases", url("http://dl.bintray.com/content/scala-js/scala-js-releases"))(Resolver.ivyStylePatterns), libraryDependencies ++= Seq( bootstrap, fontawesome, - jquery, - picklingPlay + jquery ) ) dependsOn(uav) @@ -60,8 +58,7 @@ object ApplicationBuild extends Build { libraryDependencies ++= Seq( rx, dom, - tag, - pickling + tag ) ) ) diff --git a/project/Dependencies.scala b/project/Dependencies.scala index 2afcbb1..6c705eb 100644 --- a/project/Dependencies.scala +++ b/project/Dependencies.scala @@ -15,8 +15,5 @@ object Dependencies { val dom = "org.scala-lang.modules.scalajs" %%%! "scalajs-dom" % "0.6" val tag = "com.scalatags" %%%! "scalatags" % "0.4.1" val rx = "com.scalarx" %%%! "scalarx" % "0.2.6" - val pickling = "org.scalajs" %%%! "scalajs-pickling" % "0.3.1" - val picklingPlay = "org.scalajs" %% "scalajs-pickling-play-json" % "0.3.1" - - + } \ No newline at end of file diff --git a/project/plugins.sbt b/project/plugins.sbt index 2c768c0..6678905 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,7 +1,7 @@ resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/" // The Play plugin -addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.3.4") +addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.3.6") // Scala.js plugin addSbtPlugin("org.scala-lang.modules.scalajs" % "scalajs-sbt-plugin" % "0.5.5") \ No newline at end of file diff --git a/project/util.scala b/project/util.scala index 1415ba8..993fa40 100644 --- a/project/util.scala +++ b/project/util.scala @@ -1,32 +1,37 @@ import sbt._ -import sbt.Keys._ -import play._ -import play.PlayImport.PlayKeys._ -import scala.scalajs.sbtplugin.ScalaJSPlugin -import scala.scalajs.sbtplugin.ScalaJSPlugin.ScalaJSKeys._ +import Keys._ +import play.Play._ +import scala.scalajs.sbtplugin.ScalaJSPlugin._ +import ScalaJSKeys._ +import com.typesafe.sbt.packager.universal.UniversalKeys + +package object util extends UniversalKeys { + + val scalajsOutputDir = Def.settingKey[File]("directory for javascript files output by scalajs") -package object util { implicit class ScalaJSPlayProject(val project: Project) { - def dependsOnJs(reference: Project): Project = project.settings( - resourceGenerators in Compile += Def.task{ - val outDir: File = (resourceManaged in Compile).value / "public" / "lib" - - val optimized: Seq[File] = (fastOptJS in (reference, Compile)).value.allCode.map(_.path).map(file(_)) - - val outFiles = optimized.map(file => outDir / file.name) - - for ((opt, out) <- optimized zip outFiles) { - if (!out.exists || out.lastModified < opt.lastModified) { - IO.copyFile(opt, out, true) - val map = opt.getParentFile / (out.name + ".map") - IO.copyFile(map, outDir / map.name) - } - } - outFiles - }.taskValue, - playMonitoredFiles += (scalaSource in (reference, Compile)).value.getCanonicalPath + + private def copySourceMapsTask(scalajs: Project) = Def.task { + val scalaFiles = (Seq(scalajs.base) ** ("*.scala")).get + for (scalaFile <- scalaFiles) { + val target = new File((classDirectory in Compile).value, scalaFile.getPath) + IO.copyFile(scalaFile, target) + } + } + + def dependsOnJs(scalajs: Project): Project = project.settings( + scalajsOutputDir := (classDirectory in Compile).value / "public" / "lib", + compile in Compile <<= (compile in Compile) dependsOn (fastOptJS in (scalajs, Compile)) dependsOn copySourceMapsTask(scalajs), + dist <<= dist dependsOn (fullOptJS in (scalajs, Compile)), + stage <<= stage dependsOn (fullOptJS in (scalajs, Compile)) + ).settings( + // ask scalajs project to put its outputs in scalajsOutputDir + Seq(packageLauncher, fastOptJS, fullOptJS) map { packageJSKey => + crossTarget in (scalajs, Compile, packageJSKey) := scalajsOutputDir.value + } : _* ) + } } \ No newline at end of file -- cgit v1.2.3