-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.sbt
510 lines (478 loc) · 20 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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
import scalajsbundler.sbtplugin.ScalaJSBundlerPlugin.autoImport.useYarn
import java.nio.file.Files
import java.nio.file.StandardCopyOption.REPLACE_EXISTING
import scala.sys.process.{ Process, _ }
lazy val `scalajs-react-world` = (project in file("."))
.aggregate(calendar)
.aggregate(`chat-backend`)
.aggregate(`chat-frontend`)
.aggregate(dashboard)
.aggregate(`gif-finder`)
.aggregate(`graph-viewer`)
.aggregate(heroes)
.aggregate(journal)
.aggregate(laminar)
.aggregate(`simple-test`)
.settings(commands += Command.command("chat-release") { state =>
"chat-frontend/clean" ::
"chat-frontend/fullOptJS::webpack" ::
"chat-backend/clean" ::
"chat-backend/compile" ::
"chat-backend/stage" ::
state
})
lazy val calendar =
(project in file("modules/calendar"))
.enablePlugins(ScalablyTypedConverterPlugin)
.enablePlugins(ScalaJSPlugin)
.configure(baseSettings, browserProject, reactNpmDeps, bundlerSettings, withCssLoading)
.settings(
addCommandAlias("calendar", "project calendar;fastOptJS::startWebpackDevServer;~fastOptJS"),
webpackDevServerPort := 8008,
stFlavour := Flavour.ScalajsReact,
libraryDependencies ++= Seq("com.github.japgolly.scalacss" %%% "ext-react" % "1.0.0"),
stIgnore ++= List("bootstrap", "@fortawesome/fontawesome-free"),
Compile / npmDependencies ++= NpmDependencies.`calendar`
)
lazy val `chat-backend` = (project in file("modules/chat/chat-backend"))
.configs(IntegrationTest)
.settings(Defaults.itSettings)
.settings(IntegrationTest / parallelExecution := false)
.settings(scalaVersion := "2.13.8", organization := "io.github.mvillafuertem")
.settings(testFrameworks := Seq(new TestFramework("zio.test.sbt.ZTestFramework")))
.settings(
Compile / unmanagedResourceDirectories += baseDirectory.value / "../chat-frontend/target/build",
libraryDependencies ++= Seq(
"dev.zio" %% "zio-interop-reactivestreams" % "1.3.10",
"dev.zio" %% "zio-logging-slf4j" % "0.5.14",
"dev.zio" %% "zio-streams" % "1.0.14",
"dev.zio" %% "zio" % "1.0.14",
"com.typesafe.akka" %% "akka-http" % "10.2.9",
"com.typesafe.akka" %% "akka-stream" % "2.6.19",
"com.typesafe.akka" %% "akka-actor-typed" % "2.6.19",
"com.typesafe.akka" %% "akka-slf4j" % "2.6.19",
"org.mongodb.scala" %% "mongo-scala-driver" % "4.7.0",
"ch.qos.logback" % "logback-classic" % "1.4.0",
"org.http4s" %% "http4s-dsl" % "0.23.11",
"org.http4s" %% "http4s-blaze-server" % "0.23.12",
"com.github.t3hnar" %% "scala-bcrypt" % "4.3.0",
"dev.zio" %% "zio-test" % "1.0.14" % IntegrationTest,
"dev.zio" %% "zio-test-sbt" % "1.0.14" % IntegrationTest,
"org.scalatest" %% "scalatest" % "3.2.12" % IntegrationTest,
"com.dimafeng" %% "testcontainers-scala-core" % "0.40.7" % IntegrationTest,
"com.github.jwt-scala" %% "jwt-circe" % "9.0.6"
)
)
.configure(DockerSettings.value)
.enablePlugins(JavaAppPackaging)
.dependsOn(`chat-shared`.jvm)
lazy val `chat-frontend` = (project in file("modules/chat/chat-frontend"))
.enablePlugins(ScalablyTypedConverterPlugin)
.enablePlugins(ScalaJSPlugin)
.configure(
WebpackSettings.value,
reactNpmDeps
)
.settings(
addCommandAlias("chat-frontend", "project chat-frontend;set javaOptions += \"-DIsLocal=true\";fastOptJS::startWebpackDevServer;~fastOptJS"),
scalaJSLinkerConfig ~= (_.withModuleKind(ModuleKind.CommonJSModule)),
// scalaJSLinkerConfig ~= (_.withModuleSplitStyle(ModuleSplitStyle.SmallestModules)),
stFlavour := Flavour.ScalajsReact,
libraryDependencies ++= Seq("com.github.japgolly.scalacss" %%% "ext-react" % "1.0.0"),
stIgnore ++= List("bootstrap", "@fortawesome/fontawesome-free"),
Compile / npmDependencies ++= NpmDependencies.`chat-frontend`,
Compile / npmDevDependencies ++= NpmDependencies.`chat-frontend-dev`
)
.settings(
scalaJSUseMainModuleInitializer := true,
libraryDependencies ++= Seq(
"org.scala-js" %%% "scalajs-dom" % "2.1.0"
)
)
.dependsOn(`chat-shared`.js)
.settings(
scalaVersion := "2.13.8",
organization := "io.github.mvillafuertem",
libraryDependencies ++= Seq(
"dev.zio" %%% "zio" % "1.0.14",
"io.github.cquiroz" %%% "scala-java-time" % "2.4.0",
"org.scalatest" %%% "scalatest" % "3.2.12" % Test,
"io.circe" %%% "circe-optics" % "0.14.1",
"io.circe" %%% "circe-generic" % "0.14.2"
) ++ Seq(
"com.softwaremill.sttp.client3" %%% "core",
"com.softwaremill.sttp.client3" %%% "circe"
).map(_ % sttpVersion)
)
lazy val tapirVersion = "0.17.9"
lazy val sttpVersion = "3.5.2"
lazy val `chat-shared` = crossProject(JSPlatform, JVMPlatform)
.crossType(CrossType.Pure)
.in(file("modules/chat/chat-shared"))
.settings(
scalaVersion := "2.13.8",
organization := "io.github.mvillafuertem"
)
.settings(
libraryDependencies ++= Seq(
"io.circe" %% "circe-generic" % "0.14.2"
) ++ Seq(
"com.softwaremill.sttp.tapir" %% "tapir-akka-http-server",
"com.softwaremill.sttp.tapir" %% "tapir-json-circe",
"com.softwaremill.sttp.tapir" %% "tapir-openapi-docs",
"com.softwaremill.sttp.tapir" %% "tapir-openapi-circe-yaml",
"com.softwaremill.sttp.tapir" %% "tapir-zio",
"com.softwaremill.sttp.tapir" %% "tapir-sttp-client"
).map(_ % tapirVersion)
)
lazy val `countdown-native` =
(project in file("modules/countdown-native"))
.enablePlugins(ScalaJSPlugin)
.enablePlugins(ScalablyTypedConverterExternalNpmPlugin)
.settings(
scalaVersion := "2.13.8",
scalaJSLinkerConfig ~= (_.withModuleKind(ModuleKind.CommonJSModule)),
scalaJSUseMainModuleInitializer := false,
/* ScalablyTypedConverterExternalNpmPlugin requires that we define how to install node dependencies and where they are */
externalNpm := {
Process("yarn", baseDirectory.value).!
baseDirectory.value
},
stFlavour := Flavour.ScalajsReact,
run := {
(Compile / fastOptJS).value
Process("expo start", baseDirectory.value).!
}
)
lazy val `counter-native` =
(project in file("modules/counter-native"))
.enablePlugins(ScalaJSPlugin)
.enablePlugins(ScalablyTypedConverterExternalNpmPlugin)
.settings(
scalaVersion := "2.13.8",
scalaJSLinkerConfig ~= (_.withModuleKind(ModuleKind.CommonJSModule)),
scalaJSUseMainModuleInitializer := false,
externalNpm := {
Process("yarn", baseDirectory.value).!
baseDirectory.value
},
stFlavour := Flavour.ScalajsReact,
run := {
(Compile / fastOptJS).value
Process("yarn react-native start", baseDirectory.value).!
}
)
lazy val `gif-finder` =
(project in file("modules/gif-finder"))
.enablePlugins(ScalablyTypedConverterPlugin)
.enablePlugins(ScalaJSPlugin)
.configure(baseSettings, browserProject, reactNpmDeps, bundlerSettings, withCssLoading)
.settings(
addCommandAlias("gif-finder", "project gif-finder;fastOptJS::startWebpackDevServer;~fastOptJS"),
webpackDevServerPort := 8008,
stFlavour := Flavour.Slinky,
libraryDependencies ++= Seq("me.shadaj" %%% "slinky-hot" % "0.7.2")
)
lazy val `graph-viewer` =
(project in file("modules/graph-viewer"))
.enablePlugins(ScalablyTypedConverterExternalNpmPlugin)
// .configure(baseSettings, browserProject, reactNpmDeps, bundlerSettings, withCssLoading)
.settings(
// addCommandAlias("graph-viewer", "project graph-viewer;fastOptJS::startWebpackDevServer;~fastOptJS"),
scalaJSLinkerConfig ~= { _.withModuleKind(ModuleKind.ESModule) },
scalaJSUseMainModuleInitializer := true,
scalaVersion := "2.13.8",
externalNpm := {
Process("yarn", baseDirectory.value).!
baseDirectory.value
},
webpackDevServerPort := 8008,
stFlavour := Flavour.ScalajsReact
)
lazy val heroes =
(project in file("modules/heroes"))
.enablePlugins(ScalablyTypedConverterPlugin)
.enablePlugins(ScalaJSPlugin)
.configure(baseSettings, browserProject, reactNpmDeps, bundlerSettings, withCssLoading)
.settings(
addCommandAlias("heroes", "project heroes;fastOptJS::startWebpackDevServer;~fastOptJS"),
webpackDevServerPort := 8008,
stFlavour := Flavour.Slinky,
libraryDependencies ++= Seq("me.shadaj" %%% "slinky-hot" % "0.7.2"),
Compile / npmDependencies ++= Seq(
"react-router-dom" -> "5.1.2",
"@types/react-router-dom" -> "5.1.2",
"query-string" -> "6.13.1"
)
)
lazy val journal =
(project in file("modules/journal"))
.enablePlugins(ScalablyTypedConverterPlugin)
.enablePlugins(ScalaJSPlugin)
.configure(baseSettings, browserProject, reactNpmDeps, bundlerSettings, withCssLoading)
.settings(
addCommandAlias("journal", "project journal;fastOptJS::startWebpackDevServer;~fastOptJS"),
webpackDevServerPort := 8008,
stFlavour := Flavour.ScalajsReact,
libraryDependencies ++= Seq("com.github.japgolly.scalacss" %%% "ext-react" % "1.0.0"),
Compile / npmDependencies ++= NpmDependencies.`journal`
)
lazy val dashboard =
(project in file("modules/dashboard"))
.enablePlugins(ScalablyTypedConverterPlugin)
.enablePlugins(ScalaJSPlugin)
.configure(baseSettings, browserProject, reactNpmDeps, bundlerSettings)
.settings(
addCommandAlias("dashboard", "project dashboard;fastOptJS::startWebpackDevServer;~fastOptJS"),
useYarn := true,
webpackDevServerPort := 8008,
stFlavour := Flavour.Slinky,
libraryDependencies ++= Seq("me.shadaj" %%% "slinky-hot" % "0.7.2"),
Compile / npmDependencies ++= NpmDependencies.`dashboard`
)
lazy val `expense-tracker-native` =
(project in file("modules/expense-tracker-native"))
.enablePlugins(ScalaJSPlugin)
.enablePlugins(ScalablyTypedConverterExternalNpmPlugin)
.settings(
scalaVersion := "2.13.8",
scalaJSLinkerConfig ~= (_.withModuleKind(ModuleKind.CommonJSModule)),
scalaJSUseMainModuleInitializer := false,
/* ScalablyTypedConverterExternalNpmPlugin requires that we define how to install node dependencies and where they are */
externalNpm := {
Process("yarn", baseDirectory.value).!
baseDirectory.value
},
stFlavour := Flavour.ScalajsReact,
run := {
(Compile / fastOptJS).value
Process("expo start", baseDirectory.value).!
},
libraryDependencies ++= Seq(
"com.softwaremill.sttp.client3" %%% "core" % "3.6.0",
"com.softwaremill.sttp.client3" %%% "circe" % "3.6.0",
"io.circe" %%% "circe-optics" % "0.14.1",
"io.circe" %%% "circe-generic" % "0.14.2"
)
)
val yarnBuild = taskKey[Unit]("fullOptJS then webpack")
val yarnBuildFast = taskKey[Unit]("fastOptJS then webpack")
val yarnRunDemo = taskKey[Unit]("fastOptJS then run webpack server")
lazy val laminar = (project in file("modules/laminar"))
.enablePlugins(ScalaJSPlugin)
.enablePlugins(ScalablyTypedConverterExternalNpmPlugin)
.settings(
scalaVersion := "2.13.8",
scalaJSLinkerConfig ~= { _.withModuleKind(ModuleKind.ESModule) },
scalaJSUseMainModuleInitializer := true,
stTypescriptVersion := "4.3",
externalNpm := {
Process("yarn", baseDirectory.value).!
baseDirectory.value
},
libraryDependencies += "com.raquo" %%% "laminar" % "0.14.2",
// Watch non-scala assets, when they change trigger sbt
// if you are using ~npmBuildFast, you get a rebuild
// when non-scala assets change
watchSources += baseDirectory.value / "public",
yarnBuild := {
(Compile / fullOptJS).value
"yarn --cwd modules/laminar/ run app" !
},
yarnBuildFast := {
(Compile / fastOptJS).value
"yarn --cwd modules/laminar/ run app:dev" !
},
yarnRunDemo := {
(Compile / fastOptJS).value
"yarn --cwd modules/laminar/ run app:dev-start" !
}
)
lazy val `login-native` =
(project in file("modules/login-native"))
.enablePlugins(ScalaJSPlugin)
.enablePlugins(ScalablyTypedConverterExternalNpmPlugin)
.settings(
scalaVersion := "2.13.8",
scalaJSLinkerConfig ~= (_.withModuleKind(ModuleKind.CommonJSModule)),
scalaJSUseMainModuleInitializer := false,
/* ScalablyTypedConverterExternalNpmPlugin requires that we define how to install node dependencies and where they are */
externalNpm := {
Process("yarn", baseDirectory.value).!
baseDirectory.value
},
stFlavour := Flavour.ScalajsReact,
run := {
(Compile / fastOptJS).value
Process("expo start", baseDirectory.value).!
},
libraryDependencies ++= Seq(
"com.softwaremill.sttp.client3" %%% "core" % "3.6.0",
"com.softwaremill.sttp.client3" %%% "circe" % "3.6.0",
"io.circe" %%% "circe-optics" % "0.14.1",
"io.circe" %%% "circe-generic" % "0.14.2"
)
)
lazy val `pokedex-native` =
(project in file("modules/pokedex-native"))
.enablePlugins(ScalaJSPlugin)
.enablePlugins(ScalablyTypedConverterExternalNpmPlugin)
.settings(
scalaVersion := "2.13.8",
scalaJSLinkerConfig ~= (_.withModuleKind(ModuleKind.CommonJSModule)),
scalaJSUseMainModuleInitializer := false,
externalNpm := {
Process("yarn", baseDirectory.value).!
baseDirectory.value
},
stFlavour := Flavour.ScalajsReact,
run := {
(Compile / fastOptJS).value
Process("yarn react-native start", baseDirectory.value).!
}
)
lazy val `simple-test` =
(project in file("modules/simple-test"))
.enablePlugins(ScalablyTypedConverterPlugin)
.enablePlugins(ScalaJSPlugin)
.configure(testConfiguration, reactNpmDeps, browserProject)
.settings(
addCommandAlias("simple-test", "project simple-test;fastOptJS::startWebpackDevServer;~fastOptJS"),
scalaVersion := "2.13.8",
useYarn := true,
Compile / npmDependencies ++= NpmDependencies.`simple-test`,
Compile / npmDevDependencies ++= Seq(
"file-loader" -> "6.0.0",
"style-loader" -> "1.2.1",
"css-loader" -> "3.5.3",
"html-webpack-plugin" -> "4.3.0",
"copy-webpack-plugin" -> "5.1.1",
"webpack-merge" -> "4.2.2"
),
libraryDependencies ++= Seq(
"me.shadaj" %%% "slinky-hot" % "0.7.2",
"org.scalatest" %%% "scalatest" % "3.2.12" % Test
),
stFlavour := Flavour.Slinky,
fastOptJS / webpackBundlingMode := BundlingMode.LibraryOnly(),
fastOptJS / webpackConfigFile := Some(baseDirectory.value / "webpack" / "webpack-fastopt.config.js"),
fastOptJS / webpackDevServerExtraArgs := Seq("--inline", "--hot"),
fullOptJS / webpackConfigFile := Some(baseDirectory.value / "webpack" / "webpack-opt.config.js"),
scalacOptions += "-Ymacro-annotations",
startWebpackDevServer / version := "3.11.0",
webpack / version := "4.43.0",
webpackResources := baseDirectory.value / "webpack" * "*"
)
lazy val testConfiguration: Project => Project =
_.settings(
Test / requireJsDomEnv := true,
Test / webpackConfigFile := Some(baseDirectory.value / "webpack" / "webpack-core.config.js"),
stIgnore := List(
"react-proxy",
"jss-plugin-props-sort",
"jss-props-sort",
"jss",
"jss-vendor-prefixer",
"jss-default-unit",
"jss-camel-case",
"jss-nested",
"jss-global",
"jss-plugin-nested"
),
Compile / npmDependencies ++= Seq(
"jss-props-sort" -> "6.0.0",
"jss-vendor-prefixer" -> "8.0.1",
"jss-default-unit" -> "8.0.2",
"jss-camel-case" -> "6.1.0",
"jss-nested" -> "6.0.1",
"jss-global" -> "3.0.0",
"jss-plugin-global" -> "10.4.0",
"jss-plugin-nested" -> "10.4.0",
"jss-plugin-props-sort" -> "10.4.0",
"jss" -> "10.4.0"
)
)
lazy val withCssLoading: Project => Project =
_.settings(
/* custom webpack file to include css */
webpackConfigFile := Some((ThisBuild / baseDirectory).value / "webpack" / "custom.webpack.config.js"),
Compile / npmDevDependencies ++= NpmDependencies.`withCssLoading`
)
lazy val reactNpmDeps: Project => Project =
_.settings(
Compile / npmDependencies ++= NpmDependencies.`reactNpmDeps`
)
/**
* Custom task to start demo with webpack-dev-server, use as `<project>/start`. Just `start` also works, and starts all frontend demos
*
* After that, the incantation is this to watch and compile on change: `~<project>/fastOptJS::webpack`
*/
lazy val start = TaskKey[Unit]("start")
/**
* Say just `dist` or `<project>/dist` to make a production bundle in `docs` for github publishing
*/
lazy val dist = TaskKey[File]("dist")
lazy val baseSettings: Project => Project =
_.enablePlugins(ScalaJSPlugin)
.settings(
useYarn := true,
scalaVersion := "2.13.8",
scalacOptions ++= ScalacOptions.flags,
scalacOptions += "-Ymacro-annotations",
scalaJSUseMainModuleInitializer := true,
scalaJSLinkerConfig ~= ( /* disabled because it somehow triggers many warnings */
_.withSourceMap(false)
.withModuleKind(ModuleKind.CommonJSModule)
),
libraryDependencies ++= Seq(
"dev.zio" %%% "zio" % "1.0.14",
"io.github.cquiroz" %%% "scala-java-time" % "2.4.0",
"org.scalatest" %%% "scalatest" % "3.2.12" % Test,
"com.softwaremill.sttp.client3" %%% "core" % "3.6.0",
"com.softwaremill.sttp.client3" %%% "circe" % "3.6.0",
"io.circe" %%% "circe-optics" % "0.14.1",
"io.circe" %%% "circe-generic" % "0.14.2"
)
)
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"
)
/**
* Implement the `start` and `dist` tasks defined above. Most of this is really just to copy the index.html file around.
*/
lazy val browserProject: Project => Project =
_.settings(
start := {
(Compile / fastOptJS / startWebpackDevServer).value
},
dist := {
val artifacts = (Compile / fullOptJS / webpack).value
val artifactFolder = (Compile / fullOptJS / crossTarget).value
val distFolder = (ThisBuild / baseDirectory).value / "docs" / moduleName.value
println(artifacts)
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)
}
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
}
)