Created by @jmarinotero
1. A shared project, with common code (i.e. pure Scala and ported libraries)
2. A JVM project, with JVM platform specific dependencies and code
3. A JS project, with JS platform specific dependencies and code
For example:
def checkDate(date: String, dateFormat: String): Boolean = {
DateUtils.isDate(date, dateFormat)
}
DateUtils.isDate is platform specific, depending on which platform we are running the relevant implementation will be executed.
def isDate(date: String, dateFormat: String): Boolean = {
try {
val format = new SimpleDateFormat(dateFormat)
format.setLenient(false)
val date = format.parse(date)
true
} catch {
case ex: Exception => false
}
}
def isDate(date: String, dateFormat: String): Boolean = {
try {
val year = s.substring(0, 4).toInt
val month = s.substring(4, 6).toInt - 1
val day = s.substring(6, 8).toInt
val date = new Date(year, month, day)
true
} catch {
case ex: Exception => false
}
}
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.4")
In build.sbt
val library = crossProject.settings(
libraryDependencies += "org.scalatest" %%% "scalatest" % "3.0.0"
).jsSettings(
// JS-specific settings here
).jvmSettings(
// JVM-specific settings here
)
lazy val js = library.js
lazy val jvm = library.jvm