-
Notifications
You must be signed in to change notification settings - Fork 5
/
build.sbt
183 lines (166 loc) · 6.77 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
import sbtcrossproject.{CrossProject, CrossType, Platform}
import scala.util.chaining._
val Version = new {
val Cats = "2.12.0"
val CatsEffect = "3.5.7"
val Circe = "0.14.10"
val DisciplineMunit = "2.0.0"
val Http4s = "1.0.0-M43"
val Java = "17"
val Log4Cats = "2.7.0"
val Munit = "1.0.2"
val MunitCatsEffect = "2.0.0"
val MunitScalacheck = "1.0.0"
val Scala213 = "2.13.15"
val Scala3 = "3.3.3"
val ScalajsDom = "2.8.0"
val Sconfig = "1.8.1"
val Shapeless = "2.3.12"
val Slf4j = "2.0.16"
}
def module(
identifier: Option[String],
platforms: List[Platform] = List(JVMPlatform, JSPlatform),
crossType: CrossType = CrossType.Pure
): CrossProject = {
val path = identifier.map(_.split('-').mkString("/")).fold(".")("modules/" + _)
CrossProject(identifier.getOrElse("root"), file(path))(platforms: _*)
.crossType(crossType)
.pipe { builder =>
platforms match {
case platform :: Nil => builder.withoutSuffixFor(platform)
case _ => builder
}
}
.build()
.settings(
name := "babel" + identifier.fold("")("-" + _)
)
}
ThisBuild / scalaVersion := Version.Scala3
ThisBuild / crossScalaVersions := Version.Scala213 :: Version.Scala3 :: Nil
ThisBuild / developers := List(Developer("taig", "Niklas Klein", "[email protected]", url("https://taig.io/")))
ThisBuild / dynverVTagPrefix := false
ThisBuild / homepage := Some(url("https://github.com/taig/babel/"))
ThisBuild / licenses := List("MIT" -> url("https://raw.githubusercontent.com/taig/babel/main/LICENSE"))
ThisBuild / organization := "io.taig"
ThisBuild / organizationHomepage := Some(url("https://taig.io/"))
ThisBuild / versionScheme := Some("early-semver")
lazy val root = module(identifier = None, platforms = List(JVMPlatform))
.enablePlugins(BlowoutYamlPlugin)
.settings(noPublishSettings)
.settings(
blowoutGenerators ++= {
val workflows = (LocalRootProject / baseDirectory).value / ".github" / "workflows"
BlowoutYamlGenerator.lzy(workflows / "main.yml", GithubActionsGenerator.main(Version.Java)) ::
BlowoutYamlGenerator.lzy(workflows / "pull-request.yml", GithubActionsGenerator.pullRequest(Version.Java)) ::
BlowoutYamlGenerator.lzy(workflows / "tag.yml", GithubActionsGenerator.tag(Version.Java)) ::
Nil
}
)
.aggregate(core, cats, loader, generic, circe, documentation, tests, sampleCore, sampleBackend, sampleFrontend)
lazy val core = module(identifier = Some("core")).settings(
Compile / sourceGenerators += Def.task {
val pkg = s"${organization.value}.babel"
val languages = (Compile / sourceManaged).value / "Languages.scala"
IO.write(languages, JavaLocalesGenerator.languages(pkg))
val countries = (Compile / sourceManaged).value / "Countries.scala"
IO.write(countries, JavaLocalesGenerator.countries(pkg))
val locales = (Compile / sourceManaged).value / "Locales.scala"
IO.write(locales, JavaLocalesGenerator.locales(pkg))
val stringFormatN = (Compile / sourceManaged).value / "StringFormatN.scala"
IO.write(stringFormatN, JavaLocalesGenerator.stringFormatN(pkg))
Seq(languages, countries, locales, stringFormatN)
}.taskValue
)
lazy val cats = module(identifier = Some("cats"))
.settings(
libraryDependencies ++=
"org.typelevel" %%% "cats-core" % Version.Cats ::
Nil
)
.dependsOn(core)
lazy val loader = module(identifier = Some("loader"))
.settings(
libraryDependencies ++=
"org.ekrich" %%% "sconfig" % Version.Sconfig ::
"org.typelevel" %%% "cats-effect-kernel" % Version.CatsEffect ::
Nil
)
.dependsOn(core)
lazy val generic = module(identifier = Some("generic"))
.settings(
libraryDependencies ++=
(if (scalaVersion.value == Version.Scala3) Nil else "com.chuusai" %%% "shapeless" % Version.Shapeless :: Nil)
)
.dependsOn(core)
lazy val circe = module(identifier = Some("circe"))
.settings(
libraryDependencies ++=
"io.circe" %%% "circe-parser" % Version.Circe ::
Nil
)
.dependsOn(core)
lazy val documentation = module(identifier = Some("documentation"), platforms = List(JVMPlatform))
.enablePlugins(MdocPlugin, ParadoxPlugin, ParadoxMaterialThemePlugin)
.settings(noPublishSettings)
.settings(
Compile / paradox / sourceDirectory := mdocOut.value,
Compile / unmanagedResourceDirectories += baseDirectory.value / ".." / "resources",
libraryDependencies ++=
"org.http4s" %% "http4s-ember-server" % Version.Http4s ::
Nil,
mdocIn := baseDirectory.value / ".." / "src",
mdocVariables := Map(
"ORGANIZATION" -> organization.value,
"ARTIFACT" -> "babel",
"VERSION" -> version.value
),
paradox := (Compile / paradox).dependsOn(mdoc.toTask("")).value
)
.dependsOn(core, loader, generic)
lazy val tests = module(identifier = Some("tests"), crossType = CrossType.Full)
.settings(noPublishSettings)
.settings(
libraryDependencies ++=
"org.scalameta" %%% "munit" % Version.Munit % "test" ::
"org.typelevel" %%% "cats-laws" % Version.Cats % "test" ::
"org.typelevel" %%% "discipline-munit" % Version.DisciplineMunit % "test" ::
"org.typelevel" %%% "munit-cats-effect" % Version.MunitCatsEffect % "test" ::
"org.scalameta" %%% "munit-scalacheck" % Version.MunitScalacheck % "test" ::
Nil,
testFrameworks += new TestFramework("munit.Framework")
)
.dependsOn(cats, generic, loader)
lazy val sampleCore = module(identifier = Some("sample-core"))
.settings(noPublishSettings)
.dependsOn(core, generic)
lazy val sampleBackend = module(identifier = Some("sample-backend"), platforms = List(JVMPlatform))
.enablePlugins(SbtWeb)
.settings(noPublishSettings)
.settings(
Assets / pipelineStages := Seq(scalaJSPipeline),
Compile / compile := ((Compile / compile) dependsOn scalaJSPipeline).value,
Runtime / managedClasspath += (Assets / packageBin).value,
libraryDependencies ++=
"org.http4s" %% "http4s-dsl" % Version.Http4s ::
"org.http4s" %% "http4s-ember-server" % Version.Http4s ::
"org.slf4j" % "slf4j-simple" % Version.Slf4j ::
"org.typelevel" %% "log4cats-slf4j" % Version.Log4Cats ::
Nil,
scalaJSProjects := Seq(sampleFrontend.js)
)
.dependsOn(sampleCore, loader, circe)
lazy val sampleFrontend = module(identifier = Some("sample-frontend"), platforms = List(JSPlatform))
.enablePlugins(ScalaJSWeb)
.settings(noPublishSettings)
.settings(
libraryDependencies ++=
"org.scala-js" %%% "scalajs-dom" % Version.ScalajsDom ::
"org.typelevel" %%% "cats-effect" % Version.CatsEffect ::
Nil,
scalaJSUseMainModuleInitializer := true
)
.dependsOn(sampleCore, circe)
addCommandAlias("start", s";${sampleFrontend.js.id}/fastOptJS;${sampleBackend.jvm.id}/reStart")
addCommandAlias("stop", s"${sampleBackend.jvm.id}/reStop")