Skip to content

Commit

Permalink
v0.2.1-SNAPSHOT: improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
lhns committed May 14, 2020
1 parent 9fef05d commit fe0699a
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 16 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
@@ -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"))

Expand Down
Original file line number Diff line number Diff line change
@@ -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._

Expand All @@ -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),
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
}
18 changes: 7 additions & 11 deletions src/main/scala/de/lolhens/sbt/scalajs/webjar/WebjarProject.scala
Original file line number Diff line number Diff line change
@@ -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._

Expand All @@ -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"
}
8 changes: 7 additions & 1 deletion src/sbt-test/sbt-scalajs-webjar/simple/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit fe0699a

Please sign in to comment.