-
Notifications
You must be signed in to change notification settings - Fork 4
/
ts-build.sbt
30 lines (21 loc) · 948 Bytes
/
ts-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
import scala.sys.process.Process
PlayKeys.playRunHooks += baseDirectory.map(NpmRunHook.apply).value
val Success = 0
val Error = 1
def runOnCommandline(script: String)(implicit dir: File): Int = Process(script, dir) !
def runNpmInstall(implicit dir: File): Int =
runOnCommandline(NpmCommands.dependencyInstall)
// Execute task if node modules are installed, else return Error status.
def ifNodeModulesInstalled(task: => Int)(implicit dir: File): Int =
if (runNpmInstall == Success) {
task
} else {
Error
}
def executeProdBuild(implicit dir: File): Int = ifNodeModulesInstalled(runOnCommandline(NpmCommands.build))
lazy val `ts-prod-build` = taskKey[Unit]("Run TS build when packaging the application.")
`ts-prod-build` := {
implicit val userInterfaceRoot: File = baseDirectory.value / "npm"
if (executeProdBuild != Success) throw new Exception("Oops! TS Build crashed.")
}
dist := (dist dependsOn `ts-prod-build`).value