-
Notifications
You must be signed in to change notification settings - Fork 11
/
build.sbt
159 lines (128 loc) · 3.8 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
val V = new {
val Scala = "3.2.2"
val laminar = "0.14.5"
val http4s = "0.23.18"
val http4sDom = "0.2.8"
val circe = "0.14.5"
val decline = "2.4.1"
val organiseImports = "0.6.0"
val weaver = "0.8.3"
}
val Dependencies = new {
private val http4sModules =
Seq("dsl", "ember-client", "ember-server", "circe").map("http4s-" + _)
private val sttpModules = Seq("core", "circe")
lazy val frontend = Seq(
libraryDependencies ++=
Seq(
"org.http4s" %%% "http4s-client" % V.http4s,
"org.http4s" %%% "http4s-circe" % V.http4s,
"org.http4s" %%% "http4s-dom" % V.http4sDom,
"com.raquo" %%% "laminar" % V.laminar
)
)
lazy val backend = Seq(
libraryDependencies ++=
http4sModules.map("org.http4s" %% _ % V.http4s) ++
Seq("com.monovore" %% "decline" % V.decline)
)
lazy val shared = Def.settings(
libraryDependencies += "io.circe" %%% "circe-core" % V.circe
)
lazy val tests = Def.settings(
libraryDependencies += "com.disneystreaming" %%% "weaver-cats" % V.weaver % Test,
testFrameworks += new TestFramework("weaver.framework.CatsEffect")
)
}
inThisBuild(
Seq(
scalafixDependencies += "com.github.liancheng" %% "organize-imports" % V.organiseImports,
semanticdbEnabled := true,
semanticdbVersion := scalafixSemanticdb.revision
)
)
lazy val root =
project.in(file(".")).aggregate(frontend, backend, shared.js, shared.jvm)
lazy val frontend = project
.in(file("modules/frontend"))
.dependsOn(shared.js)
.enablePlugins(ScalaJSPlugin)
.settings(scalaJSUseMainModuleInitializer := true)
.settings(
Dependencies.frontend,
Dependencies.tests,
Test / jsEnv := new org.scalajs.jsenv.jsdomnodejs.JSDOMNodeJSEnv()
)
.settings(commonBuildSettings)
lazy val backend = project
.in(file("modules/backend"))
.dependsOn(shared.jvm)
.settings(Dependencies.backend)
.settings(Dependencies.tests)
.settings(commonBuildSettings)
.enablePlugins(JavaAppPackaging)
.enablePlugins(DockerPlugin)
.settings(
Test / fork := true,
Docker / mappings += {
val appJs = (frontend / Compile / fullOptJS).value.data
appJs -> "/opt/docker/resources/prod.js"
},
Universal / javaOptions ++= Seq(
"--port 8080",
"--mode prod"
),
Docker / packageName := "laminar-http4s-example"
)
lazy val shared = crossProject(JSPlatform, JVMPlatform)
.crossType(CrossType.Pure)
.in(file("modules/shared"))
.jvmSettings(Dependencies.shared)
.jsSettings(Dependencies.shared)
.jsSettings(commonBuildSettings)
.jvmSettings(commonBuildSettings)
lazy val fastOptCompileCopy = taskKey[Unit]("")
val jsPath = "modules/backend/src/main/resources"
fastOptCompileCopy := {
val source = (frontend / Compile / fastOptJS).value.data
IO.copyFile(
source,
baseDirectory.value / jsPath / "dev.js"
)
}
lazy val fullOptCompileCopy = taskKey[Unit]("")
fullOptCompileCopy := {
val source = (frontend / Compile / fullOptJS).value.data
IO.copyFile(
source,
baseDirectory.value / jsPath / "prod.js"
)
}
lazy val commonBuildSettings: Seq[Def.Setting[?]] = Seq(
scalaVersion := V.Scala
)
addCommandAlias("runDev", ";fastOptCompileCopy; backend/reStart --mode dev")
addCommandAlias("runProd", ";fullOptCompileCopy; backend/reStart --mode prod")
val scalafixRules = Seq(
"OrganizeImports",
"DisableSyntax",
"LeakingImplicitClassVal",
"NoValInForComprehension"
).mkString(" ")
val CICommands = Seq(
"clean",
"backend/compile",
"backend/test",
"frontend/compile",
"frontend/fastOptJS",
"frontend/test",
"scalafmtCheckAll",
s"scalafix --check $scalafixRules"
).mkString(";")
val PrepareCICommands = Seq(
"scalafmtAll",
"scalafmtSbt",
s"scalafix $scalafixRules"
).mkString(";")
addCommandAlias("ci", CICommands)
addCommandAlias("preCI", PrepareCICommands)