Skip to content
This repository has been archived by the owner on Jul 30, 2024. It is now read-only.

Commit

Permalink
Merge pull request #13 from exoego/conditional-compile
Browse files Browse the repository at this point in the history
Introduce conditional compile
  • Loading branch information
TATSUNO Yasuhiro authored Jun 30, 2019
2 parents d87864e + a38ca13 commit ba73036
Show file tree
Hide file tree
Showing 169 changed files with 91 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ import org.scalatest.FunSpec
*/
class FsTest extends FunSpec {

val TEST_RESOURCES = "./app/nodejs_v8/src/test/resources/"
final val testResources = "./app/current/src/test/resources/"

describe("Fs") {

it("supports watching files") {
val watcher = Fs.watch(s"${TEST_RESOURCES}", (eventType, file) => {
val watcher = Fs.watch(s"${testResources}", (eventType, file) => {
info(s"watcher: eventType = '$eventType' file = '$file'")
})
info(s"watcher: ${Util.inspect(watcher)}")

setImmediate(
() =>
Fs.writeFile(s"${TEST_RESOURCES}1.txt", "Hello", error => {
Fs.writeFile(s"${testResources}1.txt", "Hello", error => {
if (isDefined(error)) {
alert(s"error: ${JSON.stringify(error)}")
}
Expand All @@ -33,9 +33,9 @@ class FsTest extends FunSpec {
}

it("should stream data") {
val file1 = s"${TEST_RESOURCES}fileA1.txt"
val file2 = s"${TEST_RESOURCES}fileA2.txt"
val file3 = s"${TEST_RESOURCES}fileC2.txt"
val file1 = s"${testResources}fileA1.txt"
val file2 = s"${testResources}fileA2.txt"
val file3 = s"${testResources}fileC2.txt"

val readable = Fs.createReadStream(file1)
val writable = Fs.createWriteStream(file2)
Expand All @@ -60,8 +60,8 @@ class FsTest extends FunSpec {
}

it("should pipe data from a Readable to a Writable") {
val file1 = s"${TEST_RESOURCES}fileB1.txt"
val file2 = s"${TEST_RESOURCES}fileB2.txt"
val file1 = s"${testResources}fileB1.txt"
val file2 = s"${testResources}fileB2.txt"

val readable = Fs.createReadStream(file1)
val writable = Fs.createWriteStream(file2)
Expand Down
78 changes: 61 additions & 17 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ val supportedScalaVersion = Seq(scala212Version, scala213Version)

val scalatestVersion = "3.0.8"
val scalacticVersion = "3.0.8"
val enableIfVersion = "1.1.7"

organization in ThisBuild := "net.exoego"

Expand All @@ -18,10 +19,12 @@ lazy val commonSettings = Seq(
"-unchecked",
"-feature",
"-language:implicitConversions",
"-Xlint",
"-Xfatal-warnings"
"-Xlint"
),
scalacOptions in (Compile, doc) ++= Seq("-no-link-warnings")
scalacOptions in (Compile, doc) ++= Seq(
"-Xfatal-warnings",
"-no-link-warnings"
)
)
lazy val commonScalaJsSettings = Seq(
scalacOptions += "-P:scalajs:sjsDefinedByDefault",
Expand All @@ -43,13 +46,14 @@ lazy val commonMacroParadiseSetting = Seq(
}
)
val nonPublishingSetting = Seq(
skip in publish := true,
publishArtifact := false,
publish := {},
publishLocal := {}
)

lazy val root = (project in file("."))
.aggregate(core, common, nodejs_v8)
.aggregate(core, current, nodejs_v8)
.settings(commonSettings)
.settings(publishingSettings)
.settings(nonPublishingSetting)
Expand All @@ -70,40 +74,80 @@ lazy val core = (project in file("./core"))
)
)

lazy val common = (project in file("./app/common"))
lazy val compilerSwitches = (project in file("./compiler-switches"))
.settings(commonSettings)
.settings(nonPublishingSetting)
.settings(
libraryDependencies ++= Seq(
"org.scala-lang" % "scala-reflect" % scalaVersion.value
)
)

lazy val current = (project in file("./app/current"))
.enablePlugins(ScalaJSPlugin)
.settings(commonSettings)
.settings(commonScalaJsSettings)
.settings(commonMacroParadiseSetting)
.settings(publishingSettings)
.settings(
name := "scala-js-nodejs-common",
scalacOptions ++= Seq(
"-Xmacro-settings:nodeJs12.5.0"
),
name := "scala-js-nodejs-v12",
libraryDependencies ++= Seq(
"org.scala-lang" % "scala-reflect" % scalaVersion.value,
"org.scalactic" %% "scalactic" % scalacticVersion,
"org.scalatest" %%% "scalatest" % scalatestVersion % "test"
"org.scala-lang" % "scala-reflect" % scalaVersion.value,
"org.scalactic" %% "scalactic" % scalacticVersion,
"org.scalatest" %%% "scalatest" % scalatestVersion % "test",
"com.thoughtworks.enableIf" %% "enableif" % enableIfVersion
)
)
.dependsOn(core)
.dependsOn(core, compilerSwitches)

lazy val nodejs_v8 = (project in file("./app/nodejs_v8"))
.dependsOn(common)
lazy val nodejs_v10 = (project in file("./app/nodejs-v10"))
.enablePlugins(ScalaJSPlugin)
.settings(commonSettings)
.settings(commonScalaJsSettings)
.settings(commonMacroParadiseSetting)
.settings(publishingSettings)
.settings(
unmanagedSourceDirectories in Compile += (baseDirectory in current).value / "src" / "main" / "scala",
scalacOptions ++= Seq(
"-Xmacro-settings:nodeJs10.16.0"
),
name := "scala-js-nodejs-v10",
description := "NodeJS v10.16.0 API for Scala.js",
homepage := Some(url("https://github.com/exoego/scala-js-nodejs")),
libraryDependencies ++= Seq(
"org.scala-lang" % "scala-reflect" % scalaVersion.value,
"org.scalactic" %% "scalactic" % scalacticVersion,
"org.scalatest" %%% "scalatest" % scalatestVersion % "test",
"com.thoughtworks.enableIf" %% "enableif" % enableIfVersion
)
)
.dependsOn(core, compilerSwitches)

lazy val nodejs_v8 = (project in file("./app/nodejs-v8"))
.enablePlugins(ScalaJSPlugin)
.settings(commonSettings)
.settings(commonScalaJsSettings)
.settings(commonMacroParadiseSetting)
.settings(publishingSettings)
.settings(
unmanagedSourceDirectories in Compile += (baseDirectory in current).value / "src" / "main" / "scala",
scalacOptions ++= Seq(
"-Xmacro-settings:nodeJs8.16.0"
),
name := "scala-js-nodejs-v8",
description := "NodeJS v8.7.0 API for Scala.js",
description := "NodeJS v8.16.0 API for Scala.js",
homepage := Some(url("https://github.com/exoego/scala-js-nodejs")),
libraryDependencies ++= Seq(
"org.scala-lang" % "scala-reflect" % scalaVersion.value,
"org.scalactic" %% "scalactic" % scalacticVersion,
"org.scalatest" %%% "scalatest" % scalatestVersion % "test"
"org.scala-lang" % "scala-reflect" % scalaVersion.value,
"org.scalactic" %% "scalactic" % scalacticVersion,
"org.scalatest" %%% "scalatest" % scalatestVersion % "test",
"com.thoughtworks.enableIf" %% "enableif" % enableIfVersion
)
)
.dependsOn(core)
.dependsOn(core, compilerSwitches)

lazy val publishingSettings = Seq(
licenses := Seq("APL2" -> url("http://www.apache.org/licenses/LICENSE-2.0.txt")),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package io.scalajs.nodejs

import scala.reflect.macros.whitebox

object CompilerSwitches {

private val nodejsVersionPattern = "^nodeJs([0-9]{1,2})\\.([0-9]{1,2})\\.([0-9]{1,2})$".r

private def compare(predicate: (Int, Int, Int) => Boolean): String => Boolean = { version: String =>
val nodejsVersionPattern(major, minor, patch) = version
predicate(major.toInt, minor.toInt, patch.toInt)
}

final val isNodeJs8 = (c: whitebox.Context) => c.settings.exists(compare((major, _, _) => major == 8))
final val gteNodeJs8 = (c: whitebox.Context) => c.settings.exists(compare((major, _, _) => major >= 8))

final val isNodeJs10 = (c: whitebox.Context) => c.settings.exists(compare((major, _, _) => major == 10))
final val gteNodeJs10 = (c: whitebox.Context) => c.settings.exists(compare((major, _, _) => major >= 10))

final val isNodeJs12 = (c: whitebox.Context) => c.settings.exists(compare((major, _, _) => major == 12))
final val gteNodeJs12 = (c: whitebox.Context) => c.settings.exists(compare((major, _, _) => major >= 12))
}

0 comments on commit ba73036

Please sign in to comment.