Don't require manually running npm install before the JS tests

This commit is contained in:
Alexandre Archambault
2018-03-12 21:50:35 +01:00
parent c98393838a
commit b1fde7291d
4 changed files with 29 additions and 11 deletions
+24
View File
@@ -1,4 +1,6 @@
import java.nio.file.Files
import sbt._
import sbt.Keys._
import sbt.ScriptedPlugin.autoImport.{sbtLauncher, scriptedBufferLog, ScriptedLaunchConf, scriptedLaunchOpts}
@@ -45,6 +47,28 @@ object Settings {
javacOptions.in(Keys.doc) := Seq()
)
val runNpmInstallIfNeeded = Def.task {
val baseDir = baseDirectory.in(ThisBuild).value
val evFile = baseDir / "node_modules" / ".npm_run"
val log = streams.value.log
if (!evFile.exists()) {
val cmd = Seq("npm", "install")
val b = new ProcessBuilder(cmd: _*)
b.directory(baseDir)
b.inheritIO()
log.info(s"Running ${cmd.mkString(" ")}")
val p = b.start()
val retCode = p.waitFor()
if (retCode == 0)
log.info(s"${cmd.mkString(" ")} ran successfully")
else
sys.error(s"${cmd.mkString(" ")} failed (return code $retCode)")
// Parent dir should have been created by npm install
Files.write(evFile.toPath, Array.emptyByteArray)
}
}
lazy val shared = javaScalaPluginShared ++ Seq(
scalaVersion := scala212,
libs ++= {