Permalink
Browse files

Get plotly-js version from build via property file

  • Loading branch information...
alexarchambault committed Oct 23, 2018
1 parent fb18a1a commit 53faa2f6ca27a5d7347f784c6c0f1dc39cc3d1b2
View
@@ -44,7 +44,33 @@ lazy val render = crossProject(JVMPlatform, JSPlatform)
libraryDependencies += Deps.argonautShapeless.value
)
.jvmSettings(
libraryDependencies += WebDeps.plotlyJs
libraryDependencies ++= Seq(
WebDeps.plotlyJs,
Deps.scalaTest % "test"
),
resourceGenerators.in(Compile) += Def.task {
import sys.process._
val dir = classDirectory.in(Compile).value / "plotly"
val ver = version.value
val f = dir / "plotly-scala.properties"
dir.mkdirs()
val p = new java.util.Properties
p.setProperty("plotly-js-version", WebDeps.Versions.plotlyJs)
p.setProperty("version", ver)
p.setProperty("commit-hash", Seq("git", "rev-parse", "HEAD").!!.trim)
val w = new java.io.FileOutputStream(f)
p.store(w, "plotly-scala properties")
w.close()
state.value.log.info(s"Wrote $f")
Seq(f)
}
)
.jsSettings(
libraryDependencies += Deps.scalajsDom.value
View
@@ -3,9 +3,13 @@ import sbt._
object WebDeps {
object Versions {
def plotlyJs = "1.41.3"
}
def bootstrap = "org.webjars.bower" % "bootstrap" % "3.3.6"
def jquery = "org.webjars.bower" % "jquery" % "2.2.4"
def plotlyJs = "org.webjars.bower" % "plotly.js" % "1.41.3"
def plotlyJs = "org.webjars.bower" % "plotly.js" % Versions.plotlyJs
def prism = "org.webjars.bower" % "prism" % "1.5.0"
}
@@ -10,7 +10,7 @@ import java.nio.file.Files
import argonaut.Argonaut._
import argonaut.PrettyParams
import plotly.internals.BetterPrinter
import plotly.internals.{BetterPrinter, Properties}
import scala.annotation.tailrec
@@ -58,7 +58,8 @@ object Plotly {
buffer.toByteArray
}
val plotlyVersion = "1.12.0" // FIXME Get from build.sbt
def plotlyVersion: String =
Properties.plotlyJsVersion
def plotlyMinJs: String = {
var is: InputStream = null
@@ -0,0 +1,26 @@
package plotly.internals
import java.util.{Properties => JProperties}
object Properties {
private lazy val props = {
val p = new JProperties
try {
p.load(
getClass
.getClassLoader
.getResourceAsStream("plotly/plotly-scala.properties")
)
}
catch {
case _: NullPointerException =>
}
p
}
lazy val plotlyJsVersion = props.getProperty("plotly-js-version")
lazy val version = props.getProperty("version")
lazy val commitHash = props.getProperty("commit-hash")
}
@@ -0,0 +1,11 @@
package plotly
import org.scalatest.PropSpec
class ResourceTests extends PropSpec {
property("plotly.min.js must be found in resources") {
assert(Plotly.plotlyMinJs.nonEmpty)
}
}

0 comments on commit 53faa2f

Please sign in to comment.