forked from shadaj/slinky
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sbt
224 lines (190 loc) · 6.56 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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
ThisBuild / organization := "me.shadaj"
Global / onChangedBuildSource := ReloadOnSourceChanges
turbo := true
addCommandAlias("style", "compile:scalafix; test:scalafix; compile:scalafmt; test:scalafmt; scalafmtSbt")
addCommandAlias(
"styleCheck",
"compile:scalafix --check; test:scalafix --check; compile:scalafmtCheck; test:scalafmtCheck; scalafmtSbtCheck"
)
val scala212 = "2.12.14"
val scala213 = "2.13.6"
val scala3 = "3.0.1"
ThisBuild / scalaVersion := scala213
ThisBuild / semanticdbEnabled := true
lazy val slinky = project
.in(file("."))
.aggregate(
readWrite,
core,
web,
history,
reactrouter,
testRenderer,
native,
vr,
hot,
scalajsReactInterop
)
.settings(
publish := {},
publishLocal := {}
)
addCommandAlias(
"publishSignedAll",
(slinky: ProjectDefinition[ProjectReference]).aggregate
.map(p => s"+ ${p.asInstanceOf[LocalProject].project}/publishSigned")
.mkString(";")
)
lazy val crossScalaSettings = Seq(
crossScalaVersions := Seq(scala212, scala213, scala3),
Compile / unmanagedSourceDirectories ++= {
val sourceDir = (Compile / sourceDirectory).value
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((3, _)) => Seq(sourceDir / "scala-2.13+")
case Some((2, n)) if n >= 13 => Seq(sourceDir / "scala-2.13+")
case _ => Seq(sourceDir / "scala-2.13-")
}
},
Test / unmanagedSourceDirectories ++= {
val sourceDir = (Test / sourceDirectory).value
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((3, _)) => Seq(sourceDir / "scala-2.13+")
case Some((2, n)) if n >= 13 => Seq(sourceDir / "scala-2.13+")
case _ => Seq(sourceDir / "scala-2.13-")
}
}
)
lazy val crossScala2OnlySettings =
(crossScalaVersions := Seq(scala212, scala213)) +: crossScalaSettings.tail
lazy val librarySettings = Seq(
scalacOptions += {
val origVersion = version.value
val githubVersion = if (origVersion.contains("-")) {
origVersion.split('-').last
} else {
s"v$origVersion"
}
val a = baseDirectory.value.toURI
val g = "https://raw.githubusercontent.com/shadaj/slinky"
val opt = if (scalaVersion.value == scala3) "-scalajs-mapSourceURI" else "-P:scalajs:mapSourceURI"
s"$opt:$a->$g/$githubVersion/${baseDirectory.value.getName}/"
},
scalacOptions ++= Seq(
"-encoding",
"UTF-8",
"-feature",
"-language:implicitConversions"
) ++ (CrossVersion.partialVersion(scalaVersion.value) match {
case Some((3, _)) =>
Seq(
"-unchecked",
"-source:3.0-migration"
)
case _ =>
Seq(
"-deprecation",
"-language:higherKinds",
"-Ywarn-unused:imports,privates,locals"
)
})
)
lazy val macroAnnotationSettings = Seq(
resolvers += Resolver.sonatypeRepo("releases"),
scalacOptions ++= {
if (scalaVersion.value == scala213) Seq("-Ymacro-annotations")
else Seq.empty
},
libraryDependencies ++= {
if (scalaVersion.value == scala212)
Seq(compilerPlugin(("org.scalamacros" % "paradise" % "2.1.1").cross(CrossVersion.full)))
else Seq.empty
}
)
lazy val generator = project
lazy val readWrite = project.settings(librarySettings, crossScalaSettings)
lazy val core = project
.settings(
Compile / resourceGenerators += Def.task {
val rootFolder = (Compile / resourceManaged).value / "META-INF"
rootFolder.mkdirs()
IO.write(
rootFolder / "intellij-compat.json",
s"""{
| "artifact": "me.shadaj % slinky-core-ijext_2.12 % ${version.value}"
|}""".stripMargin
)
Seq(rootFolder / "intellij-compat.json")
},
macroAnnotationSettings,
librarySettings,
crossScalaSettings
)
.dependsOn(readWrite)
lazy val web = project
.settings(
Compile / sourceGenerators += Def
.taskDyn[Seq[File]] {
val rootFolder = (Compile / sourceManaged).value / "slinky/web"
rootFolder.mkdirs()
val html = (generator / Compile / runMain)
.toTask(
Seq("slinky.generator.Generator", "web/html.json", (rootFolder / "html").getAbsolutePath, "slinky.web.html")
.mkString(" ", " ", "")
)
.map(_ => (rootFolder / "html" ** "*.scala").get)
val svg = (generator / Compile / runMain)
.toTask(
Seq("slinky.generator.Generator", "web/svg.json", (rootFolder / "svg").getAbsolutePath, "slinky.web.svg")
.mkString(" ", " ", "")
)
.map(_ => (rootFolder / "svg" ** "*.scala").get)
html.zip(svg).flatMap(t => t._1.flatMap(h => t._2.map(s => h ++ s)))
}
.taskValue,
Compile / packageSrc / mappings ++= {
val base = (Compile / sourceManaged).value
val files = (Compile / managedSources).value
files.map(f => (f, f.relativeTo(base).get.getPath))
},
librarySettings,
crossScalaSettings
)
.dependsOn(core)
lazy val history = project.settings(librarySettings, crossScala2OnlySettings)
lazy val reactrouter =
project
.settings(macroAnnotationSettings, librarySettings, crossScala2OnlySettings)
.dependsOn(core, web, history)
lazy val testRenderer = project.settings(macroAnnotationSettings, librarySettings, crossScalaSettings).dependsOn(core)
lazy val native =
project
.settings(macroAnnotationSettings, librarySettings, crossScala2OnlySettings)
.dependsOn(core, testRenderer % Test)
lazy val vr =
project
.settings(macroAnnotationSettings, librarySettings, crossScala2OnlySettings)
.dependsOn(core, testRenderer % Test)
lazy val hot = project.settings(macroAnnotationSettings, librarySettings, crossScalaSettings).dependsOn(core)
val scalaJSVersion =
Option(System.getenv("SCALAJS_VERSION")).getOrElse("1.6.0")
lazy val scalajsReactInterop = project
.settings(
macroAnnotationSettings,
librarySettings,
crossScalaSettings
)
.dependsOn(core, web % Test)
lazy val tests =
project.settings(librarySettings, macroAnnotationSettings, crossScalaSettings).dependsOn(core, web, hot)
lazy val docsMacros = project.settings(macroAnnotationSettings).dependsOn(web, hot)
lazy val docs =
project.settings(librarySettings, macroAnnotationSettings).dependsOn(web, hot, docsMacros, reactrouter, history)
ThisBuild / updateIntellij := {}
val intelliJVersion = "203.6682.168" // 2020.3
lazy val coreIntellijSupport = project.settings(
org.jetbrains.sbtidea.Keys.buildSettings :+ (
intellijBuild := intelliJVersion
): _*
)
ThisBuild / intellijBuild := intelliJVersion
ThisBuild / packageMethod := PackagingMethod.Skip()