-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.sbt
88 lines (74 loc) · 2.94 KB
/
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import scala.sys.process.Process
ThisBuild / version := "1.0.0"
ThisBuild / scalaVersion := "3.3.1"
val circeVersion = "0.14.1"
lazy val `shared-logic` = crossProject(JSPlatform, JVMPlatform)
.in(file("./shared-logic"))
.settings(
// circe for jvm-js communication
libraryDependencies ++= List(
"io.circe" %%% "circe-core",
"io.circe" %%% "circe-generic",
"io.circe" %%% "circe-parser"
).map(_ % circeVersion)
)
lazy val server = project
.in(file("./server"))
.settings(
libraryDependencies ++= List(
// cask as server (other choices are zio-http, http4s, akka-http, play...)
"com.lihaoyi" %% "cask" % "0.9.1"
),
assembly / mainClass := Some("server.Server"),
assembly / assemblyJarName := "app.jar"
)
.dependsOn(`shared-logic`.jvm)
def esModule = Def.settings(scalaJSLinkerConfig ~= {
_.withModuleKind(ModuleKind.ESModule)
})
lazy val frontend = project
.in(file("./frontend"))
.enablePlugins(ScalaJSPlugin)
.settings(
libraryDependencies ++= List(
// web framework (other choices are slinky, scala-js-react, outwatch...)
"com.raquo" %%% "laminar" % "16.0.0",
// web component library (other (non-exclusive) choices are material-ui, bootstrap...)
"be.doeraene" %%% "web-components-ui5" % "1.17.0"
),
esModule,
scalaJSUseMainModuleInitializer := true
)
.dependsOn(`shared-logic`.js)
val buildFrontend = taskKey[Unit]("Build frontend")
buildFrontend := {
/*
To build the frontend, we do the following things:
- fullLinkJS the frontend sub-module
- run npm ci in the frontend directory (might not be required)
- package the application with vite-js (output will be in the resources of the server sub-module)
*/
(frontend / Compile / fullLinkJS).value
val npmCiExit = Process(Utils.npm :: "ci" :: Nil, cwd = baseDirectory.value / "frontend").run().exitValue()
if (npmCiExit > 0) {
throw new IllegalStateException(s"npm ci failed. See above for reason")
}
val buildExit = Process(Utils.npm :: "run" :: "build" :: Nil, cwd = baseDirectory.value / "frontend").run().exitValue()
if (buildExit > 0) {
throw new IllegalStateException(s"Building frontend failed. See above for reason")
}
IO.copyDirectory(baseDirectory.value / "frontend" / "dist", baseDirectory.value / "server" / "src" / "main" / "resources" / "static")
}
(server / assembly) := (server / assembly).dependsOn(buildFrontend).value
val packageApplication = taskKey[File]("Package the whole application into a fat jar")
packageApplication := {
/*
To package the whole application into a fat jar, we do the following things:
- call sbt assembly to make the fat jar for us (config in the server sub-module settings)
- we move it to the ./dist folder so that the Dockerfile can be independent of Scala versions and other details
*/
val fatJar = (server / assembly).value
val target = baseDirectory.value / "dist" / "app.jar"
IO.copyFile(fatJar, target)
target
}