-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sbt
More file actions
158 lines (142 loc) · 5.07 KB
/
build.sbt
File metadata and controls
158 lines (142 loc) · 5.07 KB
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
import sbt.Keys.{baseDirectory, libraryDependencies}
import org.scalajs.linker.interface.{ModuleSplitStyle, OutputPatterns}
import sbtcrossproject.CrossPlugin.autoImport.{CrossType, crossProject}
import scalajscrossproject.ScalaJSCrossPlugin.autoImport.*
ThisBuild / version := "0.1.0-SNAPSHOT"
ThisBuild / scalaVersion := "3.3.5"
ThisBuild / semanticdbEnabled := true
// Define a custom task to install Git hooks
lazy val installGitHooks =
taskKey[Unit]("Install Git hooks from the .githooks directory")
installGitHooks := {
val log = streams.value.log
val gitHooksDir =
baseDirectory.value / ".githooks" // Directory containing your custom hooks
val targetDir =
baseDirectory.value / ".git" / "hooks" // Git's hooks directory
if (!targetDir.exists()) {
log.error(
"[ERROR] .git/hooks directory not found. Is this a Git repository?"
)
} else {
val hooks = (gitHooksDir * "*").get // Retrieve all files in .githooks
hooks.foreach { hook =>
val target = targetDir / hook.getName
IO.copyFile(hook, target) // Copy each hook to .git/hooks
target.setExecutable(true) // Ensure the hook is executable
}
log.success(s"[OK] Git hooks installed from ${gitHooksDir.getPath}")
}
}
// Define a flag file to indicate hooks have been installed
val hookInstalledFlag = file(".git/hooks/.hooks-installed")
lazy val installHooksIfNeeded =
taskKey[Unit]("Install Git hooks if not yet installed")
installHooksIfNeeded := Def.taskDyn {
if (!hookInstalledFlag.exists()) {
Def.task {
val log = streams.value.log
log.info("Git hooks not found — running installGitHooks...")
installGitHooks.value
IO.write(hookInstalledFlag, "installed")
log.success("Git hooks installation complete.")
}
} else
Def.task {
// streams.value.log.info("Git hooks already installed; skipping.")
}
}.value
// Automatically run the installHooksIfNeeded task when SBT starts
Global / onLoad := {
val previous = (Global / onLoad).value
state =>
val extracted = Project.extract(state)
val (newState, _) = extracted.runTask(installHooksIfNeeded, state)
previous(newState)
}
// Define a task to reset the hooks installation flag
lazy val resetHooks = taskKey[Unit]("Remove the Git hooks installation flag")
resetHooks := {
if (hookInstalledFlag.exists()) {
IO.delete(hookInstalledFlag)
println(
"[CLEANUP] Git hooks installation flag removed. Hooks will be reinstalled on next SBT startup."
)
} else
println("[INFO] No installation flag found. No action needed.")
}
lazy val backend = crossProject(JSPlatform, JVMPlatform)
.in(file("backend"))
.settings(
scalaVersion := "3.3.5"
)
.jsConfigure(_.disablePlugins(ScalafixPlugin))
.jvmSettings(
name := "backendJvm",
coverageEnabled := true,
// Backend source locations
Compile / scalaSource := baseDirectory.value.getParentFile / "src" / "main" / "scala",
Test / scalaSource := baseDirectory.value.getParentFile / "src" / "test" / "scala",
Compile / scalacOptions ++= Seq(
"-Wunused:imports"
),
libraryDependencies ++= Seq(
"org.scalatest" %% "scalatest" % "3.2.19" % Test,
"org.scalatestplus" %% "scalacheck-1-18" % "3.2.19.0" % Test
)
)
.jsSettings(
name := "backendJs",
coverageEnabled := false,
// JS-specific settings
Compile / scalaSource := baseDirectory.value.getParentFile / "src" / "main" / "scala",
Compile / fullLinkJS / scalaJSLinkerConfig ~= {
_.withModuleKind(ModuleKind.CommonJSModule)
.withModuleSplitStyle(ModuleSplitStyle.SmallModulesFor(List("casimo")))
.withCheckIR(false)
},
libraryDependencies ++= Seq(
"org.scala-js" %%% "scalajs-dom" % "2.8.0",
"com.raquo" %%% "laminar" % "17.0.0"
)
)
lazy val backendJvm = backend.jvm
lazy val backendJs = backend.js
// Frontend-specific implementation (JS only)
lazy val frontend = project
.in(file("frontend"))
.enablePlugins(ScalaJSPlugin)
.settings(
name := "casimo-frontend",
scalaVersion := "3.3.5",
coverageEnabled := false,
// Frontend source locations
Compile / scalaSource := baseDirectory.value / "src" / "main" / "scala",
Test / scalaSource := baseDirectory.value / "src" / "test" / "scala",
Compile / scalacOptions ++= Seq(
"-Wunused:imports"
),
scalaJSUseMainModuleInitializer := true,
moduleName := "casimo",
Compile / fullLinkJS / scalaJSLinkerConfig ~= {
_.withModuleKind(ModuleKind.CommonJSModule)
.withModuleSplitStyle(ModuleSplitStyle.SmallModulesFor(List("casimo")))
.withCheckIR(false)
},
libraryDependencies ++= Seq(
"it.unibo.alice.tuprolog" % "tuprolog" % "3.3.0",
"org.scala-js" %%% "scalajs-dom" % "2.8.0",
"com.raquo" %%% "laminar" % "17.0.0",
"io.github.pityka" %%% "nspl-canvas-js" % "0.9.0"
)
)
.dependsOn(backendJs)
// Root project aggregates all modules
lazy val root = project
.in(file("."))
.aggregate(backendJvm, backendJs, frontend)
.settings(
publish := {},
publishLocal := {}
)
// command sbt "coverage; backend/test; coverageReport"