-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.sbt
280 lines (256 loc) · 9.18 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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
import java.nio.file.Files
import java.nio.file.StandardCopyOption.REPLACE_EXISTING
ThisBuild / versionScheme := Some("early-semver")
// For all Sonatype accounts created on or after February 2021
ThisBuild / sonatypeCredentialHost := "s01.oss.sonatype.org"
ThisBuild / scalaVersion := "3.3.0"
inThisBuild(
List(
organization := "net.wiringbits",
name := "scala-postgres-react-admin",
scalaVersion := "3.3.0",
homepage := Some(url("https://github.com/wiringbits/scala-postgres-react-admin")),
licenses := List("MIT" -> url("https://www.opensource.org/licenses/mit-license.html")),
developers := List(
Developer(
"AlexITC",
"Alexis Hernandez",
url("https://wiringbits.net")
)
)
)
)
resolvers += Resolver.sonatypeRepo("releases")
val play = "2.9.0-M6"
val playJson = "2.10.1"
val sttp = "3.5.0"
val anorm = "2.7.0"
val scalaTestPlusPlay = "6.0.0-M6"
val scalaTestPlusMockito = "3.2.15.0"
val reactAdmin = "4.14.4"
val consoleDisabledOptions = Seq("-Xfatal-warnings", "-Ywarn-unused", "-Ywarn-unused-import")
lazy val build = TaskKey[File]("build")
// Used only by the server
lazy val baseServerSettings: Project => Project = {
_.settings(
scalacOptions ++= Seq(
"-Werror",
"-feature"
),
Compile / doc / scalacOptions ++= Seq("-no-link-warnings"),
// Some options are very noisy when using the console and prevent us using it smoothly, let's disable them
Compile / console / scalacOptions ~= (_.filterNot(consoleDisabledOptions.contains))
)
}
// Used only by play-based projects
lazy val playSettings: Project => Project = {
_.enablePlugins(PlayScala)
.disablePlugins(PlayLayoutPlugin)
.settings(
// docs are huge and unnecessary
Compile / doc / sources := Nil,
Compile / doc / scalacOptions ++= Seq(
"-no-link-warnings"
),
libraryDependencies ++= Seq(
evolutions,
"com.typesafe.play" %% "play-jdbc" % "2.9.0-M6",
"com.google.inject" % "guice" % "5.1.0"
),
// test
libraryDependencies ++= Seq(
"org.scalatestplus.play" %% "scalatestplus-play" % "6.0.0-M6" % Test,
"org.scalatestplus" %% "mockito-4-6" % scalaTestPlusMockito % Test
)
)
}
// Used only by the lib projects
lazy val baseLibSettings: Project => Project = _.settings(
scalacOptions ++= {
Seq(
"-encoding",
"UTF-8",
"-feature",
"-language:implicitConversions",
// disabled during the migration
// "-Xfatal-warnings"
"-unchecked",
"-source:3.0-migration"
)
},
libraryDependencies ++= Seq(
"org.scalatest" %%% "scalatest" % "3.2.12" % Test
)
)
// The common stuff for the server/client modules
lazy val spraCommon = (crossProject(JSPlatform, JVMPlatform) in file("spra-common"))
.configure(baseLibSettings)
.jsConfigure(_.enablePlugins(ScalaJSPlugin, ScalaJSBundlerPlugin))
.jvmSettings(
libraryDependencies ++= Seq(
// TODO: This shouldn't depend in play-json but I'm leaving it for simplicity
"com.typesafe.play" %% "play-json" % playJson
)
)
.jsSettings(
stUseScalaJsDom := true,
Test / fork := false, // sjs needs this to run tests
Compile / stMinimize := Selection.All,
libraryDependencies ++= Seq(
// TODO: This shouldn't depend in play-json but I'm leaving it for simplicity
"com.typesafe.play" %%% "play-json" % playJson
)
)
// Just the API side for the SPRA modules
lazy val spraApi = (crossProject(JSPlatform, JVMPlatform) in file("spra-api"))
.configure(baseLibSettings)
.dependsOn(spraCommon)
.jsConfigure(_.enablePlugins(ScalaJSPlugin, ScalaJSBundlerPlugin))
.jvmSettings(
libraryDependencies ++= Seq(
"com.typesafe.play" %% "play-json" % playJson,
"com.softwaremill.sttp.client3" %% "core" % sttp
)
)
.jsSettings(
stUseScalaJsDom := true,
Test / fork := false, // sjs needs this to run tests
Compile / stMinimize := Selection.All,
libraryDependencies ++= Seq(
"com.typesafe.play" %%% "play-json" % playJson,
"com.softwaremill.sttp.client3" %%% "core" % sttp
)
)
/** Includes the specific stuff to run the SPRA server side (play-specific)
*/
lazy val spraPlayServer = (project in file("spra-play-server"))
.enablePlugins(PlayScala)
.dependsOn(spraApi.jvm, spraCommon.jvm)
.configure(baseServerSettings, playSettings)
.settings(
fork := true,
Test / fork := true, // allows for graceful shutdown of containers once the tests have finished running
libraryDependencies ++= Seq(
guice,
"org.playframework.anorm" %% "anorm" % anorm,
"com.typesafe.play" %% "play-json" % playJson,
"org.postgresql" % "postgresql" % "42.3.6",
"com.github.jwt-scala" %% "jwt-core" % "9.0.5",
"de.svenkubiak" % "jBCrypt" % "0.4.3",
"commons-validator" % "commons-validator" % "1.7",
"com.dimafeng" %% "testcontainers-scala-scalatest" % "0.40.7" % "test",
"com.dimafeng" %% "testcontainers-scala-postgresql" % "0.40.7" % "test",
"com.softwaremill.sttp.client3" %% "core" % sttp % "test",
"com.softwaremill.sttp.client3" %% "async-http-client-backend-future" % sttp % "test"
)
)
lazy val bundlerSettings: Project => Project =
_.settings(
Compile / fastOptJS / webpackExtraArgs += "--mode=development",
Compile / fullOptJS / webpackExtraArgs += "--mode=production",
Compile / fastOptJS / webpackDevServerExtraArgs += "--mode=development",
Compile / fullOptJS / webpackDevServerExtraArgs += "--mode=production"
)
lazy val spraWebBuildInfoSettings: Project => Project = _.enablePlugins(BuildInfoPlugin)
.settings(
buildInfoKeys := Seq[BuildInfoKey](name, version, scalaVersion, sbtVersion),
buildInfoKeys ++= {
val apiUrl = sys.env.get("API_URL")
val values = Seq(
"apiUrl" -> apiUrl
)
// Logging these values is useful to make sure that the necessary settings
// are being overriden when packaging the app.
sLog.value.info(s"BuildInfo settings:\n${values.mkString("\n")}")
values.map(t => BuildInfoKey(t._1, t._2))
},
buildInfoPackage := "net.wiringbits",
buildInfoUsePackageAsPath := true
)
lazy val browserProject: Project => Project =
_.settings(
build := {
val artifacts = (Compile / fullOptJS / webpack).value
val artifactFolder = (Compile / fullOptJS / crossTarget).value
val jsFolder = baseDirectory.value / "src" / "main" / "js"
val distFolder = baseDirectory.value / "build"
distFolder.mkdirs()
artifacts.foreach { artifact =>
val target = artifact.data.relativeTo(artifactFolder) match {
case None => distFolder / artifact.data.name
case Some(relFile) => distFolder / relFile.toString
}
Files.copy(artifact.data.toPath, target.toPath, REPLACE_EXISTING)
}
// copy public resources
Files
.walk(jsFolder.toPath)
.filter(x => !Files.isDirectory(x))
.forEach(source => {
source.toFile.relativeTo(jsFolder).foreach { relativeSource =>
val dest = distFolder / relativeSource.toString
dest.getParentFile.mkdirs()
Files.copy(source, dest.toPath, REPLACE_EXISTING)
}
})
// link the proper js bundle
val indexFrom = baseDirectory.value / "src/main/js/index.html"
val indexTo = distFolder / "index.html"
val indexPatchedContent = {
import collection.JavaConverters._
Files
.readAllLines(indexFrom.toPath, IO.utf8)
.asScala
.map(_.replaceAllLiterally("-fastopt", "-opt"))
.mkString("\n")
}
Files.write(indexTo.toPath, indexPatchedContent.getBytes(IO.utf8))
distFolder
}
)
lazy val spraWeb = (project in file("spra-web"))
.dependsOn(spraApi.js)
.configure(bundlerSettings, baseLibSettings, browserProject, spraWebBuildInfoSettings)
.configure(_.enablePlugins(ScalaJSPlugin, ScalaJSBundlerPlugin))
.settings(
Test / fork := false, // sjs needs this to run tests
scalaJSUseMainModuleInitializer := true,
scalaJSLinkerConfig := scalaJSLinkerConfig.value.withSourceMap(false),
webpackDevServerPort := 8081,
webpackBundlingMode := BundlingMode.LibraryOnly(),
libraryDependencies ++= Seq(
"org.scala-js" %%% "scala-js-macrotask-executor" % "1.0.0",
"me.shadaj" %%% "slinky-core" % "0.7.4",
"me.shadaj" %%% "slinky-web" % "0.7.4"
),
Compile / npmDependencies ++= Seq(
"react" -> "17.0.0",
"react-dom" -> "17.0.0",
"react-scripts" -> "5.0.0",
"react-admin" -> reactAdmin,
"ra-ui-materialui" -> reactAdmin,
"ra-data-simple-rest" -> reactAdmin,
"ra-i18n-polyglot" -> reactAdmin,
"ra-language-english" -> reactAdmin,
"ra-core" -> reactAdmin,
"@mui/material" -> "5.8.1",
"@emotion/styled" -> "11.8.1"
)
)
lazy val root = (project in file("."))
.aggregate(
spraCommon.jvm,
spraCommon.js,
spraApi.jvm,
spraApi.js,
spraPlayServer,
spraWeb
)
.settings(
name := "scala-postgres-react-admin",
publish := {},
publishLocal := {},
publish / skip := true
)
addCommandAlias("spra-admin", ";spraWeb/fastOptJS::startWebpackDevServer;~spraWeb/fastOptJS")