-
Notifications
You must be signed in to change notification settings - Fork 9
/
build.sbt
143 lines (127 loc) · 5.28 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
import java.io.File
import org.scalajs.linker.interface.ModuleSplitStyle.SmallestModules
ThisBuild / version := "0.1.0"
ThisBuild / scalaVersion := "3.5.0"
ThisBuild / versionScheme := Some("early-semver")
val publicFolderDev = taskKey[String]("Returns the compiled main.js parent path for dev")
val publicFolderProd = taskKey[String]("Returns the compiled main.js parent path for production`")
val eventLister = taskKey[Seq[File]]("List all events markdown files")
val confLister = taskKey[Seq[File]]("List all events markdown files")
lazy val root = project
.in(file("."))
.enablePlugins(ScalaJSPlugin)
.settings(
name := "scalaio-website",
scalacOptions ++= Seq(
"-Yexplicit-nulls",
"-Wunused:all"
),
libraryDependencies ++= Seq(
"com.raquo" %%% "laminar" % Dependencies.laminar,
"com.raquo" %%% "waypoint" % Dependencies.waypoint,
"com.lihaoyi" %%% "upickle" % Dependencies.upickle,
"org.scala-js" %%% "scalajs-dom" % "2.4.0",
"org.foundweekends" %%% "knockoff" % "0.9.0",
"com.softwaremill.sttp.tapir" %%% "tapir-sttp-client" % "1.10.7",
"com.softwaremill.sttp.client4" %%% "core" % "4.0.0-M14",
"io.github.cquiroz" %%% "scala-java-time" % "2.5.0", // implementations of java.time classes for Scala.JS
"org.scalactic" %%% "scalactic" % "3.2.19",
"org.scalatest" %%% "scalatest" % "3.2.19" % "test"
),
scalaJSUseMainModuleInitializer := true,
scalaJSLinkerConfig ~= {
_.withModuleKind(ModuleKind.ESModule)
.withModuleSplitStyle(SmallestModules)
.withSourceMap(false)
},
confLister := sessionsListing().value,
publicFolderDev := linkerOutputDirectory((Compile / fastLinkJS).value).getAbsolutePath,
publicFolderProd := linkerOutputDirectory((Compile / fullLinkJS).value).getAbsolutePath,
Compile / sourceGenerators ++= Seq(
eventListing().taskValue,
sessionsListing().taskValue,
sponsorListing().taskValue,
confListing().taskValue
)
)
def lines(lines: String*) = lines.mkString("\n")
def slugify(name: String): String = name.toLowerCase().replace("-", "_")
def listMarkdowns(file: File): Seq[File] = file.listFiles().filter(_.getName.endsWith(".md")).toList
def listFolders(file: File): Seq[File] = file.listFiles().filter(_.isDirectory()).toList
def eventListing() = Def.task {
val file = (Compile / sourceManaged).value / "io" / "scala" / "data" / "EventsData.scala"
val events = listMarkdowns(new File("./public/scalafr-meetups"))
val content =
s"""|package io.scala.data
|
|object EventsData:
| val events = List(${events.map(file => "\"" * 3 + IO.read(file) + "\"" * 3).mkString(",")})
|""".stripMargin
if (!file.exists() || IO.read(file) != content) {
IO.write(file, content)
}
Seq(file)
}
def confListing() = Def.task {
val file = (Compile / sourceManaged).value / "io" / "scala" / "data" / "ConfsData.scala"
val conferences = listFolders(new File("./public/conferences")).map { folder =>
val conference = listMarkdowns(folder).find(_.getName == "conference.md").get
val folderSlug = slugify(folder.getName)
folderSlug -> s"""| def ${folderSlug}: String = ${"\"" * 3 + IO.read(conference) + "\"" * 3}"""
}
val content =
s"""|package io.scala.data
|
|object ConfsData {
${conferences.map(_._2).mkString("\n")}
| def all: Seq[String] = Seq(${conferences.map(x => s""""${x._1}"""").mkString(",")})
|}""".stripMargin
if (!file.exists() || IO.read(file) != content) {
IO.write(file, content)
}
Seq(file)
}
def sessionsListing() = Def.task {
val file = (Compile / sourceManaged).value / "io" / "scala" / "data" / "SessionsData.scala"
val sessionsByConf = listFolders(new File("./public/conferences")).map { folder =>
val sessions = listMarkdowns(folder).filter(_.getName != "conference.md")
s"""| def ${slugify(
folder
.getName()
)}: List[String] = List(${sessions.map(file => "\"" * 3 + IO.read(file) + "\"" * 3).mkString(",")})"""
}
val content =
s"""|package io.scala.data
|
|object SessionsData {
${sessionsByConf.mkString("\n")}
|}""".stripMargin
if (!file.exists() || IO.read(file) != content) {
IO.write(file, content)
}
Seq(file)
}
def sponsorListing() = Def.task {
val file = (Compile / sourceManaged).value / "io" / "scala" / "data" / "SponsorsData.scala"
val sponsors = listMarkdowns(new File("./public/sponsors")).map { md =>
s"""| def ${slugify(md.base)}: String = ${"\"" * 3 + IO.read(md) + "\"" * 3}"""
}
val content =
s"""|package io.scala.data
|
|object SponsorsData {
${sponsors.mkString("\n")}
|}""".stripMargin
if (!file.exists() || IO.read(file) != content) {
IO.write(file, content)
}
Seq(file)
}
def linkerOutputDirectory(v: Attributed[org.scalajs.linker.interface.Report]): File = {
v.get(scalaJSLinkerOutputDirectory.key).getOrElse {
throw new MessageOnlyException(
"Linking report was not attributed with output directory. " +
"Please report this as a Scala.js bug."
)
}
}