-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sbt
169 lines (153 loc) · 5.62 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
import org.scalajs.linker.interface.{ESFeatures, ESVersion}
import java.nio.file.Files
import java.nio.file.StandardCopyOption.REPLACE_EXISTING
Global / onChangedBuildSource := ReloadOnSourceChanges
lazy val start = TaskKey[Unit]("start")
lazy val dist = TaskKey[File]("dist")
lazy val scala3Version = "3.2.0"
lazy val catsVersion = "2.8.0"
lazy val upickleVersion = "2.0.0"
lazy val munitVersion = "1.0.0-M5"
lazy val commonSettings = Seq(
scalaVersion := scala3Version,
version := "0.0.1-SNAPSHOT",
organization := "uk.ac.bristol.uob-hpc",
organizationName := "University of Bristol",
// scalacOptions ~= filterConsoleScalacOptions,
javacOptions ++=
Seq(
"-parameters",
"-Xlint:all"
) ++
Seq("-source", "1.8") ++
Seq("-target", "1.8"),
scalacOptions ++= Seq(
// "-explain", //
"-no-indent", //
"-Wconf:cat=unchecked:error", //
"-Wconf:name=MatchCaseUnreachable:error", //
"-Wconf:name=PatternMatchExhaustivity:error" //
// "-language:strictEquality"
),
scalafmtDetailedError := true,
scalafmtFailOnErrors := true
)
lazy val model = crossProject(JSPlatform, JVMPlatform)
.settings(
commonSettings,
name := "model",
libraryDependencies ++= Seq("com.lihaoyi" %%% "upickle" % upickleVersion)
)
lazy val generator = project
.settings(
commonSettings,
name := "generator",
libraryDependencies ++= Seq(
"org.slf4j" % "slf4j-simple" % "2.0.3",
"org.eclipse.jgit" % "org.eclipse.jgit" % "6.3.0.202209071007-r",
"com.lihaoyi" %% "upickle" % "2.0.0"
),
Compile / packageBin / mainClass := Some("uob_hpc.Main"),
assemblyMergeStrategy := {
case PathList("META-INF", "versions", "9", "module-info.class") => MergeStrategy.discard
case x =>
val oldStrategy = (ThisBuild / assemblyMergeStrategy).value
oldStrategy(x)
}
)
.dependsOn(model.jvm)
lazy val webapp = project
.enablePlugins(ScalaJSPlugin, ScalablyTypedConverterPlugin)
.settings(
commonSettings,
name := "webapp",
scalaJSUseMainModuleInitializer := true,
Compile / watchTriggers += (baseDirectory.value / "src/main/js/public").toGlob / "*.*",
scalaJSLinkerConfig ~= ( //
_.withSourceMap(false)
.withModuleKind(ModuleKind.CommonJSModule)
.withESFeatures(ESFeatures.Defaults.withESVersion(ESVersion.ES2015))
.withParallel(true)
),
useYarn := true,
webpackDevServerPort := 8001,
stUseScalaJsDom := true,
webpack / version := "5.73.0",
webpackCliVersion := "4.10.0",
startWebpackDevServer / version := "4.9.3",
Compile / fastOptJS / webpackExtraArgs += "--mode=development",
Compile / fullOptJS / webpackExtraArgs += "--mode=production",
Compile / fastOptJS / webpackDevServerExtraArgs += "--mode=development",
Compile / fullOptJS / webpackDevServerExtraArgs += "--mode=production",
webpackConfigFile := Some((ThisBuild / baseDirectory).value / "webpack.config.mjs"),
libraryDependencies ++= Seq(
"org.scala-js" %%% "scalajs-dom" % "2.3.0",
"io.github.cquiroz" %%% "scala-java-time" % "2.4.0", // ignore timezones
"com.raquo" %%% "laminar" % "0.14.5",
"com.raquo" %%% "waypoint" % "0.5.0"
),
stIgnore ++= List(
"node",
"bulma",
"@fortawesome/fontawesome-free"
),
Compile / npmDependencies ++= Seq(
// CSS and layout
"@fortawesome/fontawesome-free" -> "5.15.4",
"bulma" -> "0.9.4"
),
Compile / npmDevDependencies ++= Seq(
"webpack-merge" -> "5.8.0",
"css-loader" -> "6.7.1",
"style-loader" -> "3.3.1",
"file-loader" -> "6.2.0",
"url-loader" -> "1.1.2",
"html-loader" -> "4.1.0"
)
)
.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"
distFolder.mkdirs()
IO.deleteFilesEmptyDirs(Seq(distFolder.file))
artifacts.foreach { artifact =>
val target = artifact.data.relativeTo(artifactFolder) match {
case None => distFolder / artifact.data.name
case Some(relFile) => distFolder / relFile.toString
}
IO.copy(
Seq(artifact.data.file -> target),
overwrite = true,
preserveLastModified = true,
preserveExecutable = false
)
}
val index = "index.html"
val publicResources = baseDirectory.value / "src/main/js/public/"
Files.list(publicResources.toPath).filter(_.getFileName.toString != index).forEach { p =>
Files.copy(p, (distFolder / p.getFileName.toString).toPath, REPLACE_EXISTING)
}
val indexFrom = publicResources / index
val indexTo = distFolder / index
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
}
)
.dependsOn(model.js)
lazy val root = project
.in(file("."))
.settings(commonSettings)
.aggregate(generator, model.jvm, model.js, webapp)