generated from keynmol/http4s-laminar-stack
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.sbt
192 lines (168 loc) · 6.15 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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
import org.scalajs.linker.interface.ModuleInitializer
import java.io.File
Global / onChangedBuildSource := ReloadOnSourceChanges
val V = new {
val Scala = "2.13.11"
val ScalaGroup = "2.13"
val organiseImports = "0.6.0"
}
scalaVersion := V.Scala
val Dependencies = new {
lazy val frontend = Seq(
libraryDependencies ++=
Seq(
"com.raquo" %%% "laminar" % "16.0.0",
"com.raquo" %%% "waypoint" % "7.0.0"
)
)
lazy val backend = Seq(
libraryDependencies += "com.lihaoyi" %% "cask" % "0.9.1", // webserver - https://github.com/com-lihaoyi/cask
libraryDependencies += "io.getquill" %% "quill-jdbc" % "4.6.1", // DB lib - https://getquill.io
libraryDependencies += "org.postgresql" % "postgresql" % "42.6.0", // Postgres driver, note the single %
libraryDependencies += "org.ekrich" %% "sconfig" % "1.5.0", // config - https://github.com/ekrich/sconfig
libraryDependencies += "com.lihaoyi" %% "requests" % "0.8.0" // simple http library
)
lazy val shared = Def.settings(
libraryDependencies += "com.lihaoyi" %%% "upickle" % "3.1.2" // for parsing things
)
lazy val tests = Def.settings(
libraryDependencies += "com.lihaoyi" %%% "utest" % "0.8.1" % Test
)
}
inThisBuild(
Seq(
scalafixDependencies += "com.github.liancheng" %% "organize-imports" % V.organiseImports,
semanticdbEnabled := true,
semanticdbVersion := scalafixSemanticdb.revision,
scalafixScalaBinaryVersion := V.ScalaGroup
)
)
lazy val root =
(project in file(".")).aggregate(todo, backend, shared.js, shared.jvm)
lazy val todo = (project in file("modules/frontend"))
.dependsOn(shared.js)
.enablePlugins(ScalaJSPlugin, ScalaJSBundlerPlugin, ScalablyTypedConverterPlugin)
.settings(
Dependencies.frontend,
Dependencies.tests,
testFrameworks += new TestFramework("utest.runner.Framework"),
Compile / npmDependencies += "vega-embed" -> "6.18.2",
Compile / npmDependencies += "vega" -> "5.19.1",
Compile / npmDependencies += "vega-lite" -> "4.17.0",
Compile / npmDependencies += "vega-view" -> "5.10.1",
Compile / npmDevDependencies += "html-webpack-plugin" -> "5.5.0",
Compile / npmDevDependencies += "style-loader" -> "3.3.2",
Compile / npmDevDependencies += "css-loader" -> "6.7.3",
Compile / npmDevDependencies += "mini-css-extract-plugin" -> "2.7.5",
Compile / npmDevDependencies += "webpack-merge" -> "5.8.0",
version in webpack := "5.76.3",
version in startWebpackDevServer := "3.11.2",
scalaJSLinkerConfig ~= { _.withModuleKind(ModuleKind.CommonJSModule) },
Compile / fastOptJS / scalaJSLinkerConfig ~= { _.withSourceMap(false) },
Compile / fullOptJS / scalaJSLinkerConfig ~= { _.withSourceMap(false) },
webpackEmitSourceMaps := false, // to keep compile / reload cycle fast
webpackDevServerPort := 3000,
webpackBundlingMode := BundlingMode.LibraryAndApplication(),
webpackDevServerExtraArgs := Seq("--inline"),
webpackConfigFile := Some(baseDirectory.value / "webpack.config.js"),
stIgnore += "vega-view",
scalaJSUseMainModuleInitializer := true,
requireJsDomEnv := true,
useYarn := true
)
.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 := false,
Universal / mappings += {
val appJs = (todo / Compile / fullOptJS).value.data
appJs -> ("lib/prod.js")
},
Universal / javaOptions ++= Seq(
/* "--port 8080",
"--mode prod" */
),
Docker / packageName := "laminar-cask",
testFrameworks += new TestFramework("example.backend.WithDbFramework")
)
lazy val shared = crossProject(JSPlatform, JVMPlatform)
.crossType(CrossType.Pure)
.in(file("modules/shared"))
.jvmSettings(Dependencies.shared)
.jsSettings(Dependencies.shared)
.jsSettings(commonBuildSettings)
.jvmSettings(commonBuildSettings)
.jsConfigure { project => project.enablePlugins(ScalaJSBundlerPlugin) }
lazy val fastLinkCompileCopy = taskKey[Unit]("")
val assetPath = "/src/main/resources/assets"
val jsPath = s"$assetPath/js"
fastLinkCompileCopy := {
val backendDir = baseDirectory.in(backend).value.getAbsolutePath
val files = (webpack in (todo, Compile, fastOptJS)).value
files.foreach { f =>
IO.copyFile(
f.data,
baseDirectory.in(backend).value / jsPath / f.data.name
)
}
IO.copyFile(
new File(s"""$backendDir/$assetPath/html/Index_dev.html"""),
new File(s"""$backendDir/$assetPath/Index.html""")
)
}
lazy val fullOptCompileCopy = taskKey[Unit]("")
fullOptCompileCopy := {
val backendDir = baseDirectory.in(backend).value.getAbsolutePath
val files = (webpack in (todo, Compile, fullOptJS)).value
files.foreach { f =>
IO.copyFile(
f.data,
baseDirectory.in(backend).value / jsPath / f.data.name
)
}
IO.copyFile(
new File(s"""$backendDir/$assetPath/html/Todo_prod.html"""),
new File(s"""$backendDir/$assetPath/Todo.html""")
)
}
lazy val commonBuildSettings: Seq[Def.Setting[_]] = Seq(
scalaVersion := V.Scala,
scalacOptions ++= Seq(
"-Ywarn-unused"
)
)
addCommandAlias("runDev", ";fastLinkCompileCopy; backend/reStart --mode dev")
addCommandAlias("runProd", ";fullOptCompileCopy; backend/reStart --mode prod")
val scalafixRules = Seq(
"OrganizeImports",
"DisableSyntax",
"LeakingImplicitClassVal",
"ProcedureSyntax",
"NoValInForComprehension"
).mkString(" ")
val CICommands = Seq(
"clean",
"backend/compile",
"backend/test",
"todo/test",
"todo/compile",
"todo/fastOptJS/webpack",
"todo/test",
"scalafmtCheckAll",
s"scalafix --check $scalafixRules"
).mkString(";")
val PrepareCICommands = Seq(
s"compile:scalafix --rules $scalafixRules",
s"test:scalafix --rules $scalafixRules",
"test:scalafmtAll",
"compile:scalafmtAll",
"scalafmtSbt"
).mkString(";")
addCommandAlias("ci", CICommands)
addCommandAlias("preCI", PrepareCICommands)