forked from scalawithcats/scala-with-cats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sbt
253 lines (214 loc) · 7.05 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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
import scala.sys.process._
ThisBuild / name := "scala-with-cats"
ThisBuild / organization := "com.scalawithcats"
ThisBuild / version := "0.0.1"
ThisBuild / scalaVersion := "3.3.1"
ThisBuild / useSuperShell := false
Global / logLevel := Level.Warn
enablePlugins(MdocPlugin)
mdocIn := sourceDirectory.value / "pages"
mdocOut := target.value / "pages"
val catsVersion = "2.10.0"
libraryDependencies ++= Seq(
"org.typelevel" %% "cats-core" % catsVersion,
"org.scalameta" %% "munit" % "0.7.29" % Test,
"org.scalameta" %% "munit-scalacheck" % "0.7.29" % Test
)
// addCompilerPlugin("org.typelevel" % "kind-projector" % "0.13.2" cross CrossVersion.full)
scalacOptions += "-Ykind-projector:underscores"
mdocVariables := Map(
"SCALA_VERSION" -> scalaVersion.value,
"CATS_VERSION" -> catsVersion
)
lazy val pages = List(
"preface/preface.md",
"preface/versions.md",
"preface/conventions.md",
"preface/contributors.md",
"preface/backers.md",
"intro/index.md",
"intro/three-levels.md",
"intro/what-is-fp.md",
"parts/part1.md",
"adt/index.md",
"adt/scala.md",
"adt/structural-recursion.md",
"adt/structural-corecursion.md",
"adt/applications.md",
"adt/algebra.md",
"adt/conclusions.md",
"adt-interpreters/index.md",
"adt-interpreters/regexp.md",
"adt-interpreters/reification.md",
"adt-interpreters/tail-recursion.md",
"adt-interpreters/conclusions.md",
"adt-optimization/index.md",
"adt-optimization/stack-machine.md",
"adt-optimization/effects.md",
"adt-optimization/optimization.md",
"type-classes/index.md",
"type-classes/anatomy.md",
"type-classes/implicits.md",
"type-classes/printable.md",
"type-classes/cats.md",
"type-classes/equal.md",
"type-classes/instance-selection.md",
"type-classes/summary.md",
"monoids/index.md",
"monoids/cats.md",
"monoids/applications.md",
"monoids/summary.md",
"functors/index.md",
"functors/cats.md",
"functors/contravariant-invariant.md",
"functors/contravariant-invariant-cats.md",
"functors/partial-unification.md",
"functors/summary.md",
"monads/index.md",
"monads/cats.md",
"monads/id.md",
"monads/either.md",
"monads/monad-error.md",
"monads/eval.md",
"monads/writer.md",
"monads/reader.md",
"monads/state.md",
"monads/custom-instances.md",
"monads/summary.md",
"monad-transformers/index.md",
"monad-transformers/summary.md",
"applicatives/index.md",
"applicatives/semigroupal.md",
"applicatives/examples.md",
"applicatives/parallel.md",
"applicatives/applicative.md",
"applicatives/summary.md",
"foldable-traverse/index.md",
"foldable-traverse/foldable.md",
"foldable-traverse/foldable-cats.md",
"foldable-traverse/traverse.md",
"foldable-traverse/traverse-cats.md",
"foldable-traverse/summary.md",
"parts/part2.md",
"case-studies/testing/index.md",
"case-studies/map-reduce/index.md",
"case-studies/validation/index.md",
"case-studies/validation/sketch.md",
"case-studies/validation/check.md",
"case-studies/validation/map.md",
"case-studies/validation/kleisli.md",
"case-studies/validation/conclusions.md",
"case-studies/crdt/index.md",
"case-studies/crdt/eventual-consistency.md",
"case-studies/crdt/g-counter.md",
"case-studies/crdt/generalisation.md",
"case-studies/crdt/abstraction.md",
"case-studies/crdt/summary.md",
// "case-studies/parser/index.md",
// "case-studies/parser/intro.md",
// "case-studies/parser/error-handling.md",
// "case-studies/parser/transforms.md",
// "case-studies/parser/applicative.md",
"parts/part3.md",
"solutions.md",
"links.md",
"parts/part4.md"
)
/*
The code below outlines steps to build the book:
Each build is independent (even the TeX and PDF builds).
The PDF, HTML, and ePub builds are the important ones.
Others are for debugging.
Each build involves three steps: a setup step, mdoc, and a Pandoc step.
You can run each of these steps indepdendently. For example,
running `pdf` is equivalent to `;pdfSetup; mdoc; pdfPandoc`.
The `all` task is equivalent to `;pdf ;html ;epub`,
except that it only runs `mdoc` once.
The code to build the Pandoc command-line is in `project/Pandoc.scala`.
*/
lazy val pdfSetup = taskKey[Unit]("Pre-mdoc component of the PDF build")
lazy val htmlSetup = taskKey[Unit]("Pre-mdoc component of the HTML build")
lazy val epubSetup = taskKey[Unit]("Pre-mdoc component of the ePub build")
lazy val texSetup = taskKey[Unit]("Pre-mdoc component of the TeX debug build")
lazy val jsonSetup =
taskKey[Unit]("Pre-mdoc component of the JSON AST debug build")
pdfSetup := {
"mkdir -p dist".!
}
htmlSetup := {
"mkdir -p dist src/temp".!
"npm install".!
"npx lessc --include-path=node_modules --strict-imports src/less/html.less src/temp/html.css".!
"npx browserify src/js/html.js --outfile src/temp/html.js".!
}
epubSetup := {
"mkdir -p dist src/temp".!
"npm install".!
"npx lessc --include-path=node_modules --strict-imports src/less/epub.less src/temp/epub.css".!
}
texSetup := {
"mkdir -p dist".!
}
jsonSetup := {
"mkdir -p dist".!
}
lazy val pdfPandoc = taskKey[String]("Pandoc command-line for the PDF build")
lazy val htmlPandoc = taskKey[String]("Pandoc command-line for the HTML build")
lazy val epubPandoc = taskKey[String]("Pandoc command-line for the ePub build")
lazy val texPandoc =
taskKey[String]("Pandoc command-line for the TeX debug build")
lazy val jsonPandoc =
taskKey[String]("Pandoc command-line for the JSON AST debug build")
pdfPandoc := { Pandoc.commandLineOptions(pages, PandocTarget.Pdf) }
htmlPandoc := { Pandoc.commandLineOptions(pages, PandocTarget.Html) }
epubPandoc := { Pandoc.commandLineOptions(pages, PandocTarget.Epub) }
texPandoc := { Pandoc.commandLineOptions(pages, PandocTarget.Tex) }
jsonPandoc := { Pandoc.commandLineOptions(pages, PandocTarget.Json) }
lazy val pdf = taskKey[Unit]("Build the PDF version of the book")
lazy val html = taskKey[Unit]("Build the HTML version of the book")
lazy val epub = taskKey[Unit]("Build the ePub version of the book")
lazy val tex = taskKey[Unit]("Build the TeX debug build of the book")
lazy val json = taskKey[Unit]("Build the JSON AST debug build of the book")
pdf := {
val cmdLineOptions =
Def.sequential(pdfSetup, mdoc.toTask(""), pdfPandoc).value
val cmd = s"pandoc $cmdLineOptions"
println(cmd)
streams.value.log.info(cmd)
cmd.!
}
html := {
val cmdLineOptions =
Def.sequential(htmlSetup, mdoc.toTask(""), htmlPandoc).value
val cmd = s"pandoc $cmdLineOptions"
streams.value.log.info(cmd)
cmd.!
}
epub := {
val cmdLineOptions =
Def.sequential(epubSetup, mdoc.toTask(""), epubPandoc).value
val cmd = s"pandoc $cmdLineOptions"
streams.value.log.info(cmd)
cmd.!
}
tex := {
val cmdLineOptions =
Def.sequential(texSetup, mdoc.toTask(""), texPandoc).value
val cmd = s"pandoc $cmdLineOptions"
streams.value.log.info(cmd)
cmd.!
}
json := {
val cmdLineOptions =
Def.sequential(jsonSetup, mdoc.toTask(""), jsonPandoc).value
val cmd = s"pandoc $cmdLineOptions"
streams.value.log.info(cmd)
cmd.!
}
lazy val all =
taskKey[Unit]("Build the PDF, HTML, and ePub versions of the book")
all := {
pdf.value
html.value
epub.value
}