From fe0699abf8f7c36333b4d3cbf751fce9e8f50527 Mon Sep 17 00:00:00 2001 From: Pierre Kisters Date: Thu, 14 May 2020 16:07:46 +0200 Subject: [PATCH] v0.2.1-SNAPSHOT: improvements --- build.sbt | 2 +- .../scalajs/webjar/ScalaJSWebjarPlugin.scala | 13 +++++++++++-- .../sbt/scalajs/webjar/WebjarKeys.scala | 6 +++++- .../sbt/scalajs/webjar/WebjarProject.scala | 18 +++++++----------- .../sbt-scalajs-webjar/simple/build.sbt | 8 +++++++- 5 files changed, 31 insertions(+), 16 deletions(-) diff --git a/build.sbt b/build.sbt index 291a9e4..2917028 100644 --- a/build.sbt +++ b/build.sbt @@ -1,6 +1,6 @@ organization := "de.lolhens" name := "sbt-scalajs-webjar" -version := "0.1.1-SNAPSHOT" +version := "0.2.1-SNAPSHOT" licenses += ("Apache-2.0", url("https://www.apache.org/licenses/LICENSE-2.0")) diff --git a/src/main/scala/de/lolhens/sbt/scalajs/webjar/ScalaJSWebjarPlugin.scala b/src/main/scala/de/lolhens/sbt/scalajs/webjar/ScalaJSWebjarPlugin.scala index dc8bf23..a43fa50 100644 --- a/src/main/scala/de/lolhens/sbt/scalajs/webjar/ScalaJSWebjarPlugin.scala +++ b/src/main/scala/de/lolhens/sbt/scalajs/webjar/ScalaJSWebjarPlugin.scala @@ -1,8 +1,8 @@ package de.lolhens.sbt.scalajs.webjar -import WebjarPlugin.autoImport._ -import org.scalajs.sbtplugin.ScalaJSPlugin +import de.lolhens.sbt.scalajs.webjar.WebjarPlugin.autoImport._ import org.scalajs.sbtplugin.ScalaJSPlugin.autoImport._ +import org.scalajs.sbtplugin.{ScalaJSPlugin, Stage} import sbt.Keys._ import sbt._ @@ -13,6 +13,15 @@ object ScalaJSWebjarPlugin extends AutoPlugin { Compile / fastOptJS / crossTarget := (Compile / webjarArtifacts / crossTarget).value, Compile / fullOptJS / crossTarget := (Compile / webjarArtifacts / crossTarget).value, + Compile / scalaJSLinkedFile / artifactPath := Def.settingDyn { + scalaJSStage.value match { + case Stage.FastOpt => Compile / fastOptJS / artifactPath + case Stage.FullOpt => Compile / fullOptJS / artifactPath + } + }.value, + + Compile / webjarMainResource := (Compile / webjarResourcePath).value + "/" + (Compile / scalaJSLinkedFile / artifactPath).value.getName, + Compile / webjarArtifacts := Seq( (Compile / scalaJSLinkedFile).value.data, (Compile / scalaJSLinkedFile).value.metadata(scalaJSSourceMap), diff --git a/src/main/scala/de/lolhens/sbt/scalajs/webjar/WebjarKeys.scala b/src/main/scala/de/lolhens/sbt/scalajs/webjar/WebjarKeys.scala index e746d88..0a6a56b 100644 --- a/src/main/scala/de/lolhens/sbt/scalajs/webjar/WebjarKeys.scala +++ b/src/main/scala/de/lolhens/sbt/scalajs/webjar/WebjarKeys.scala @@ -1,11 +1,15 @@ package de.lolhens.sbt.scalajs.webjar -import sbt.{File, Project, taskKey} +import sbt._ import scala.language.implicitConversions class WebjarKeys { lazy val webjarArtifacts = taskKey[Seq[File]]("WebJar artifacts.") + lazy val webjarResourcePath = settingKey[String]("Resource path of the webjar artifacts.") + + lazy val webjarMainResource = settingKey[String]("Resource path of the main webjar artifact.") + implicit def webjarProject(project: Project): WebjarProject = new WebjarProject(project) } diff --git a/src/main/scala/de/lolhens/sbt/scalajs/webjar/WebjarProject.scala b/src/main/scala/de/lolhens/sbt/scalajs/webjar/WebjarProject.scala index 5144644..d7fa853 100644 --- a/src/main/scala/de/lolhens/sbt/scalajs/webjar/WebjarProject.scala +++ b/src/main/scala/de/lolhens/sbt/scalajs/webjar/WebjarProject.scala @@ -1,7 +1,6 @@ package de.lolhens.sbt.scalajs.webjar import de.lolhens.sbt.scalajs.webjar.WebjarPlugin.autoImport._ -import de.lolhens.sbt.scalajs.webjar.WebjarProject._ import sbt.Keys._ import sbt._ @@ -12,25 +11,22 @@ class WebjarProject(val self: Project) extends AnyVal { Project(self.id + "-webjar", self.base.toPath.resolve(".webjar").toFile) .settings( name := (self / name).value + "-webjar", + normalizedName := (self / normalizedName).value + "-webjar", version := (self / version).value, scalaVersion := (self / scalaVersion).value, watchSources := (self / watchSources).value, + self / Compile / webjarResourcePath := s"META-INF/resources/webjars/${(self / name).value}/${(self / version).value}", + self / Compile / webjarArtifacts / crossTarget := { - (Compile / classDirectory).value - .toPath - .resolve(webjarPath((self / name).value, (self / version).value)) - .toFile + (Compile / classDirectory).value.toPath.resolve((self / Compile / webjarResourcePath).value).toFile }, - Compile / compile := (Compile / compile).dependsOn(self / Compile / webjarArtifacts).value + Compile / compile := (Compile / compile).dependsOn(self / Compile / webjarArtifacts).value, + + exportJars := true, ) } } - -object WebjarProject { - def webjarPath(library: String, version: String): String = - s"META-INF/resources/webjars/$library/$version" -} diff --git a/src/sbt-test/sbt-scalajs-webjar/simple/build.sbt b/src/sbt-test/sbt-scalajs-webjar/simple/build.sbt index df98aa7..e82da7a 100644 --- a/src/sbt-test/sbt-scalajs-webjar/simple/build.sbt +++ b/src/sbt-test/sbt-scalajs-webjar/simple/build.sbt @@ -20,6 +20,12 @@ lazy val backend = project .settings( name := "backend", - scalaVersion := "2.13.1" + scalaVersion := "2.13.1", + + Compile / compile := { + println((frontend / Compile / webjarMainResource).value) + + (Compile / compile).value + } ) .dependsOn(frontend.webjar)