-
Notifications
You must be signed in to change notification settings - Fork 7
/
build.sbt
161 lines (144 loc) · 7.89 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
Global / onChangedBuildSource := IgnoreSourceChanges // not working well with webpack devserver
ThisBuild / version := "0.1.0-SNAPSHOT"
ThisBuild / scalaVersion := "2.13.15"
Global / excludeLintKeys += webpackDevServerPort // TODO:
val versions = new {
val outwatch = "1.1.0"
val colibri = "0.8.6"
val funStack = "0.9.23"
val tapir = "1.11.11"
val pprint = "0.9.0"
}
// Uncomment, if you want to use snapshot dependencies from sonatype or jitpack
// ThisBuild / resolvers ++= Seq(
// "Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots",
// "Sonatype OSS Snapshots S01" at "https://s01.oss.sonatype.org/content/repositories/snapshots", // https://central.sonatype.org/news/20210223_new-users-on-s01/
// "Jitpack" at "https://jitpack.io",
// )
val enableFatalWarnings =
sys.env.get("ENABLE_FATAL_WARNINGS").flatMap(value => scala.util.Try(value.toBoolean).toOption).getOrElse(false)
lazy val commonSettings = Seq(
addCompilerPlugin("org.typelevel" % "kind-projector" % "0.13.3" cross CrossVersion.full),
// overwrite scalacOptions "-Xfatal-warnings" from https://github.com/DavidGregory084/sbt-tpolecat
if (enableFatalWarnings) scalacOptions += "-Xfatal-warnings" else scalacOptions -= "-Xfatal-warnings",
scalacOptions ++= Seq("-Ymacro-annotations", "-Vimplicits", "-Vtype-diffs"),
scalacOptions --= Seq("-Xcheckinit"), // produces check-and-throw code on every val access
)
lazy val scalaJsSettings = Seq(
scalaJSLinkerConfig ~= { _.withModuleKind(ModuleKind.CommonJSModule) },
libraryDependencies += "org.portable-scala" %%% "portable-scala-reflect" % "1.1.3",
) ++ scalaJsBundlerSettings ++ scalaJsMacrotaskExecutor ++ scalaJsSecureRandom
lazy val scalaJsBundlerSettings = Seq(
webpack / version := "5.75.0",
webpackCliVersion := "5.0.0",
startWebpackDevServer / version := "4.11.1",
useYarn := true,
)
lazy val scalaJsMacrotaskExecutor = Seq(
// https://github.com/scala-js/scala-js-macrotask-executor
libraryDependencies += "org.scala-js" %%% "scala-js-macrotask-executor" % "1.1.1",
)
lazy val scalaJsSecureRandom = Seq(
// https://www.scala-js.org/news/2022/04/04/announcing-scalajs-1.10.0
libraryDependencies += "org.scala-js" %%% "scalajs-java-securerandom" % "1.0.0",
)
def readJsDependencies(baseDirectory: File, field: String): Seq[(String, String)] = {
val packageJson = ujson.read(IO.read(new File(s"$baseDirectory/package.json")))
packageJson(field).obj.mapValues(_.str.toString).toSeq
}
lazy val webapp = project
.enablePlugins(
ScalaJSPlugin,
ScalaJSBundlerPlugin,
ScalablyTypedConverterPlugin,
)
.dependsOn(api)
.settings(commonSettings, scalaJsSettings)
.settings(
Test / test := {}, // skip tests, since we don't have any in this subproject. Remove this line, once there are tests
libraryDependencies ++= Seq(
"io.github.outwatch" %%% "outwatch" % versions.outwatch,
"io.github.fun-stack" %%% "fun-stack-client-web" % versions.funStack,
"com.github.cornerman" %%% "colibri-router" % versions.colibri,
),
Compile / npmDependencies ++= readJsDependencies(baseDirectory.value, "dependencies") ++ Seq(
"snabbdom" -> "github:outwatch/snabbdom.git#semver:0.7.5", // for outwatch, workaround for: https://github.com/ScalablyTyped/Converter/issues/293
"reconnecting-websocket" -> "4.1.10", // for fun-stack websockets, workaround for https://github.com/ScalablyTyped/Converter/issues/293 https://github.com/cornerman/mycelium/blob/6f40aa7018276a3281ce11f7047a6a3b9014bff6/build.sbt#74
"jwt-decode" -> "3.1.2", // for fun-stack auth, workaround for https://github.com/ScalablyTyped/Converter/issues/293 https://github.com/cornerman/mycelium/blob/6f40aa7018276a3281ce11f7047a6a3b9014bff6/build.sbt#74
),
stIgnore ++= List(
"reconnecting-websocket",
"snabbdom",
"jwt-decode",
),
Compile / npmDevDependencies ++= readJsDependencies(baseDirectory.value, "devDependencies"),
scalaJSUseMainModuleInitializer := true,
webpackDevServerPort := sys.env
.get("FRONTEND_PORT")
.flatMap(port => scala.util.Try(port.toInt).toOption)
.getOrElse(12345),
webpackDevServerExtraArgs := Seq("--color"),
fullOptJS / webpackEmitSourceMaps := true,
fastOptJS / webpackEmitSourceMaps := true,
fastOptJS / webpackBundlingMode := BundlingMode.LibraryOnly(),
fastOptJS / webpackConfigFile := Some(baseDirectory.value / "webpack.config.dev.js"),
fullOptJS / webpackConfigFile := Some(baseDirectory.value / "webpack.config.prod.js"),
)
// shared project which contains api definitions.
// these definitions are used for type safe implementations
// of client and server
lazy val api = project
.enablePlugins(ScalaJSPlugin)
.settings(commonSettings)
.settings(
Test / test := {}, // skip tests, since we don't have any in this subproject. Remove this line, once there are tests
libraryDependencies ++= Seq(
"com.softwaremill.sttp.tapir" %%% "tapir-core" % versions.tapir,
"com.softwaremill.sttp.tapir" %%% "tapir-json-circe" % versions.tapir,
),
)
lazy val lambda = project
.enablePlugins(
ScalaJSPlugin,
ScalaJSBundlerPlugin,
ScalablyTypedConverterPlugin,
)
.dependsOn(api)
.settings(commonSettings, scalaJsSettings, scalaJsBundlerSettings)
.settings(
Test / test := {}, // skip tests, since we don't have any in this subproject. Remove this line, once there are tests
libraryDependencies ++= Seq(
"io.github.fun-stack" %%% "fun-stack-lambda-ws-event-authorizer" % versions.funStack,
"io.github.fun-stack" %%% "fun-stack-lambda-ws-rpc" % versions.funStack,
"io.github.fun-stack" %%% "fun-stack-lambda-http-rpc" % versions.funStack,
"io.github.fun-stack" %%% "fun-stack-lambda-http-api-tapir" % versions.funStack,
"io.github.fun-stack" %%% "fun-stack-backend" % versions.funStack,
"com.lihaoyi" %%% "pprint" % versions.pprint,
),
Compile / npmDependencies ++= readJsDependencies(baseDirectory.value, "dependencies"),
stIgnore ++= List(
"aws-sdk",
),
Compile / npmDevDependencies ++= readJsDependencies(baseDirectory.value, "devDependencies"),
fullOptJS / webpackEmitSourceMaps := true,
fastOptJS / webpackEmitSourceMaps := true,
fastOptJS / webpackConfigFile := Some(baseDirectory.value / "webpack.config.dev.js"),
fullOptJS / webpackConfigFile := Some(baseDirectory.value / "webpack.config.prod.js"),
)
addCommandAlias("prod", "; lambda/fullOptJS/webpack; webapp/fullOptJS/webpack")
addCommandAlias("prodf", "webapp/fullOptJS/webpack")
addCommandAlias("prodb", "lambda/fullOptJS/webpack")
addCommandAlias("dev", "devInitAll; devWatchAll; devDestroyFrontend")
addCommandAlias("devf", "devInitFrontend; devWatchFrontend; devDestroyFrontend") // compile only frontend
addCommandAlias("devb", "devInitBackend; devWatchBackend") // compile only backend
// devInitBackend needs to execute {...}/fastOptJS/webpack, to prepare all npm dependencies.
// We want to avoid this expensive preparation in the hot-reload process,
// and therefore only watch {...}/fastOptJS, where dependencies can be resolved from the previously prepared
// node_modules folder.
addCommandAlias("devInitBackend", "lambda/fastOptJS/webpack")
addCommandAlias("devInitFrontend", "webapp/fastOptJS/startWebpackDevServer; webapp/fastOptJS/webpack")
addCommandAlias("devInitAll", "devInitFrontend; devInitBackend")
addCommandAlias("devWatchFrontend", "~; webapp/fastOptJS")
addCommandAlias("devWatchBackend", "~; lambda/fastOptJS")
addCommandAlias("devWatchAll", "~; lambda/fastOptJS; webapp/fastOptJS; compile; Test/compile")
addCommandAlias("devDestroyFrontend", "webapp/fastOptJS/stopWebpackDevServer")