-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfront-end-build.sbt
45 lines (30 loc) · 1.64 KB
/
front-end-build.sbt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import scala.sys.process.Process
val Success = 0
val Error = 1
val isWindows = System.getProperty("os.name").toLowerCase().contains("win")
PlayKeys.playRunHooks += baseDirectory.map(FrontEndRunHook.apply).value
def runOnCommandline(script: String)(implicit dir: File): Int = {
if (isWindows) {
Process("cmd /c " + script, dir)
} else {
Process(script, dir)
}
} !
def isNodeModulesInstalled(implicit dir: File): Boolean = (dir / "node_modules").exists()
def runNpmInstall(implicit dir: File): Int = if (isNodeModulesInstalled) Success else runOnCommandline(FrontEndCommands.dependencyInstall)
def ifNodeModulesInstalled(task: => Int)(implicit dir: File): Int = if (runNpmInstall == Success) task else Error
def executeUiTests(implicit dir: File): Int = ifNodeModulesInstalled(runOnCommandline(FrontEndCommands.test))
def executeProdBuild(implicit dir: File): Int = ifNodeModulesInstalled(runOnCommandline(FrontEndCommands.build))
lazy val `front-end-test` = TaskKey[Unit]("run front end tests when testing application")
`front-end-test` := {
implicit val userInterfaceRoot: File = baseDirectory.value / "front-end"
if (executeUiTests != Success) throw new Exception("Front End tests failed")
}
lazy val `front-end-prod-build` = TaskKey[Unit]("run front end build when packaging the application")
`front-end-prod-build` := {
implicit val userInterfaceRoot: File = baseDirectory.value / "front-end"
if (executeProdBuild != Success) throw new Exception("Front End Build crashed")
}
dist := (dist dependsOn `front-end-prod-build`).value
stage := (stage dependsOn `front-end-prod-build`).value
test := ((test in Test) dependsOn `front-end-test`).value