-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sbt
201 lines (155 loc) · 6.14 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
import org.scalajs.linker.interface.Report
import sys.process.*
val Scala213 = "2.13.14"
val Scala212 = "2.12.18"
val Scala3 = "3.3.3"
val scalatestVersion = "3.2.19"
val Version = "0.1"
Global / onChangedBuildSource := ReloadOnSourceChanges
Global / excludeLintKeys += dillFrontend / Compile / stMinimize
/* Handle OS specific usage of commands */
def convertCmd(cmd: String): String = (
sys.props("os.name").toLowerCase() match {
case osName if osName contains "windows" => "cmd /C " ++ cmd
case _ => cmd
}
)
/* Global project settings */
inThisBuild(List(
version := Version,
organization := "com.github.j-mie6",
organizationName := "Parsley Debug App Contributors <https://github.com/j-mie6/parsley-debug-app/graphs/contributors>",
startYear := Some(2025),
licenses := List("BSD-3-Clause" -> url("https://opensource.org/licenses/BSD-3-Clause")),
developers := List(
Developer("j-mie6", "Jamie Willis", "", url("https://github.com/j-mie6/parsley-debug-app")),
Developer("Riley-horrix", "Riley Horrix", "", url("https://github.com/j-mie6/parsley-debug-app")),
Developer("aniket1101", "Aniket Gupta", "", url("https://github.com/j-mie6/parsley-debug-app")),
Developer("PriyanshC", "Priyansh Chugh", "", url("https://github.com/j-mie6/parsley-debug-app")),
Developer("Aito0", "Alejandro Perez Fadon", "", url("https://github.com/j-mie6/parsley-debug-app")),
Developer("AdamW1087", "Adam Watson", "", url("https://github.com/j-mie6/parsley-debug-app")),
Developer("josh-ja-walker", "Josh Walker", "", url("https://github.com/j-mie6/parsley-debug-app"))
),
versionScheme := Some("early-semver"),
scalaVersion := Scala3,
))
/* Setup project dependencies */
lazy val commonSettings = Seq(
resolvers ++= Opts.resolver.sonatypeOssReleases, /* Will speed up MiMA during fast back-to-back releases */
resolvers ++= Opts.resolver.sonatypeOssSnapshots, /* Needed during flux periods */
/* Dependencies required throughout project */
libraryDependencies ++= Seq(
"org.scalatest" %%% "scalatest" % scalatestVersion % Test,
"org.scala-lang" %% "scala3-compiler" % "3.3.3"
),
/* Test settings */
Test / testOptions += Tests.Argument(TestFrameworks.ScalaTest, "-oI"),
Test / parallelExecution := false,
)
/* Setup for Laminar */
lazy val dillFrontend = project
.in(file("src-laminar"))
.enablePlugins(ScalaJSPlugin, ScalablyTypedConverterExternalNpmPlugin)
.settings(
/* Scala JS/ScalablyTyped settings */
scalaJSLinkerConfig ~= (_.withModuleKind(ModuleKind.ESModule)),
scalaJSUseMainModuleInitializer := true,
stUseScalaJsDom := true,
stIgnore += "type-fest",
Compile / stMinimize := Selection.AllExcept("types", "tauri-apps"),
/* Frontend settings */
name := "dill-frontend",
commonSettings,
libraryDependencies ++= Seq( /* Extra dependencies required for frontend */
"com.raquo" %%% "laminar" % "17.2.0",
"com.vladsch.flexmark" % "flexmark-all" % "0.61.26",
"com.lihaoyi" %%% "upickle" % "4.1.0"
),
/* Run npm to link with ScalablyTyped */
externalNpm := {
convertCmd("npm").!
println()
baseDirectory.value.getParentFile()
},
/* Compile the frontend */
Compile / packageSrc / mappings ++= {
val base = (Compile / sourceManaged).value
val files = (Compile / managedSources).value
files.map { f => (f, f.relativeTo(base).get.getPath) }
}
)
lazy val isRelease = sys.env.get("RELEASE").contains("true") /* Compile in release mode (not dev) */
/* Report frontend build setup */
lazy val reportFrontend = taskKey[(Report, File)]("")
ThisBuild / reportFrontend := {
if (isRelease) {
println("Building in release mode")
} else {
println("Building in quick compile mode. To build in release mode, set RELEASE environment variable to \"true\"")
}
(dillFrontend / Compile / fullLinkJS).value.data -> (dillFrontend / Compile / fullLinkJS / scalaJSLinkerOutputDirectory).value
}
/* Build Dill frontend */
lazy val buildFrontend = taskKey[Map[String, File]]("")
buildFrontend := {
val (report, fm) = reportFrontend.value
val outDir = (ThisBuild / baseDirectory).value / "static"
IO.listFiles(fm)
.map { file =>
val (name, ext) = file.baseAndExt
val out = outDir / (name + "." + ext)
IO.copyFile(file, out)
file.name -> out
}
.toMap
}
/* Build project into an executable */
val build = taskKey[Unit]("Build the project into packages and executables.")
build := {
val front = buildFrontend.value
convertCmd("npm run tauri build").!
}
/* Run project */
run := {
val front = buildFrontend.value
convertCmd("npm run tauri dev").!
}
/* Setup required dependencies */
lazy val setup = taskKey[Unit]("Install required dependencies")
setup := {
convertCmd("npm install").!
}
/* Build project in Docker */
val dockerBuild = taskKey[Unit]("Build the project onto a docker machine, running the application")
dockerBuild := {
print("Copying Files... ")
"scp -o StrictHostKeyChecking=no -r -P 2222 ./src ./src-tauri root@localhost:/home >> logs".!
println("done")
println("Building frontend... ")
"echo \"cd /home && sbt buildFrontend\" | ssh -o StrictHostKeyChecking=no -p 2222 root@localhost >> logs 2>&1".!
println("Done")
}
/* Clean all generated files */
val cleanHard = taskKey[Unit]("Clean")
cleanHard := {
print("Removing npm dependencies... ")
"rm -rf node_modules/".!
println("done")
print("Removing Scala files... ")
"rm -rf .metals/".!
"rm -rf .bloop/".!
"rm -rf .bsp/".!
"rm -rf .scala-build/".!
println("done")
print("Removing targets... ")
"rm -rf static/".!
println("done")
print("Removing Tauri targets... ")
"rm -rf src-tauri/target/".!
println("done")
print("Removing Laminar targets... ")
"rm -rf src-laminar/target/".!
println("done")
/* Apply default clean */
clean.value
}