-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.sc
257 lines (225 loc) · 8.04 KB
/
build.sc
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
254
255
256
257
import $ivy.`com.goyeau::mill-scalafix::0.2.11`
import com.goyeau.mill.scalafix.ScalafixModule
import mill._, mill.scalalib._, mill.scalajslib._
import mill.scalajslib.api.{ModuleKind, ModuleSplitStyle, Report}
import mill.scalalib.scalafmt._
import mill.define.Task
import mill.define.Target
import coursier.maven.MavenRepository
val thisScalaVersion = "2.13.8"
val thisScalaJSVersion = "1.12.0"
// plugins etc.
val kindProjectorVersion = "0.13.2"
val organizeImportsVersion = "0.6.0"
// scala deps
// my libs
val jjmVersion = "0.2.3"
// other deps
val circeVersion = "0.13.0"
val declineVersion = "1.0.0"
val scalaJavaTimeVersion = "2.3.0"
val scalatagsVersion = "0.8.2"
val http4sVersion = "0.21.18"
val rainierVersion = "0.3.5"
// testing
val munitVersion = "0.7.21"
val munitCatsEffectVersion = "0.13.0"
// jvm deps
val scalaCSVVersion = "1.3.10"
val logbackVersion = "1.2.3"
val osLibVersion = "0.8.0"
// scalajs deps
val scalajsDomVersion = "1.1.0"
val scalajsJqueryVersion = "1.0.0"
val scalacssVersion = "0.7.0"
val scalajsMacrotaskExecutorVersion = "1.0.0"
// raw JS
val jqueryVersion = "2.2.1"
val reactVersion = "17.0.2"
val vegaVersion = "5"
val vegaLiteVersion = "5"
val vegaEmbedVersion = "6"
// for some reason the $file import doesn't work anymore?
// import $file.`scripts-build`.SimpleJSDepsBuild, SimpleJSDepsBuild.SimpleJSDeps
trait SimpleJSDeps extends Module {
def jsDeps = T {
Agg.empty[String]
}
def downloadedJSDeps = T {
for (url <- jsDeps())
yield {
val filename = url.substring(url.lastIndexOf("/") + 1)
os.proc("curl", "-o", filename, url).call(cwd = T.ctx().dest)
T.ctx().dest / filename
}
}
def aggregatedJSDeps = T {
val targetPath = T.ctx().dest / "jsdeps.js"
os.write.append(targetPath, "")
downloadedJSDeps().foreach { path =>
os.write.append(targetPath, os.read(path))
os.write.append(targetPath, "\n")
}
PathRef(targetPath)
}
}
trait CommonModule extends ScalaModule with ScalafmtModule with ScalafixModule {
def scalaVersion = thisScalaVersion
def platformSegment: String
override def sources = T.sources(millSourcePath / "src", millSourcePath / s"src-$platformSegment")
override def repositoriesTask = T.task {
super.repositoriesTask() ++
Seq(
MavenRepository("https://oss.sonatype.org/content/repositories/snapshots"),
MavenRepository("https://dl.bintray.com/rainier/maven")
)
}
override def scalacOptions = Seq(
"-unchecked",
"-deprecation",
"-feature",
"-language:higherKinds",
"-Ymacro-annotations",
"-Ywarn-unused"
)
override def scalacPluginIvyDeps =
super.scalacPluginIvyDeps() ++ Agg(ivy"org.typelevel:::kind-projector:$kindProjectorVersion")
def scalafixIvyDeps = Agg(ivy"com.github.liancheng::organize-imports:$organizeImportsVersion")
override def ivyDeps = Agg(
// most of the FP dependencies are pulled in by JJM
ivy"org.julianmichael::jjm-core::$jjmVersion",
ivy"org.julianmichael::jjm-io::$jjmVersion",
ivy"io.circe::circe-generic-extras::$circeVersion",
ivy"io.github.cquiroz::scala-java-time::$scalaJavaTimeVersion",
ivy"com.stripe::rainier-core:$rainierVersion"
)
trait CommonTestModule extends CommonModule with TestModule.Munit {
override def scalaVersion = thisScalaVersion
override def ivyDeps = Agg(
ivy"org.scalameta::munit::$munitVersion",
ivy"org.typelevel::munit-cats-effect-2::$munitCatsEffectVersion"
)
}
}
object debate extends Module {
object jvm extends CommonModule {
def runMainFn = T.task { (mainClass: String, args: Seq[String]) =>
import mill.api.Result
import mill.modules.Jvm
try Result.Success(
Jvm.runSubprocess(
mainClass,
runClasspath().map(_.path),
forkArgs(),
forkEnv(),
args,
workingDir = forkWorkingDir(),
useCpPassingJar = runUseArgsFile()
)
)
catch {
case e: Exception =>
Result.Failure("subprocess failed")
}
}
def millSourcePath = build.millSourcePath / "debate"
def platformSegment = "jvm"
override def mainClass = T(Some("debate.Serve"))
override def ivyDeps =
super.ivyDeps() ++
Agg(
ivy"org.julianmichael::jjm-corenlp::$jjmVersion",
ivy"com.lihaoyi::os-lib:$osLibVersion",
ivy"com.monovore::decline::$declineVersion",
ivy"com.monovore::decline-effect::$declineVersion",
ivy"com.lihaoyi::scalatags:$scalatagsVersion",
ivy"org.http4s::http4s-blaze-client::$http4sVersion",
ivy"com.github.tototoshi::scala-csv::$scalaCSVVersion",
// java dependencies
ivy"ch.qos.logback:logback-classic:$logbackVersion",
ivy"io.circe::circe-generic-extras::$circeVersion"
)
object test extends super.Tests with CommonTestModule {
def moduleDeps = Seq(debate.jvm)
def platformSegment = "jvm"
}
}
object js extends CommonModule with ScalaJSModule with SimpleJSDeps {
def millSourcePath = build.millSourcePath / "debate"
def platformSegment = "js"
def scalaJSVersion = thisScalaJSVersion
// override def moduleKind = ModuleKind.ESModule
// override def moduleSplitStyle = ModuleSplitStyle.FewestModules
def mainClass = T(Some("debate.App"))
import mill.scalajslib.ScalaJSWorkerApi
import mill.scalajslib.api.{OptimizeMode, FastOpt}
// copied from
// https://github.com/com-lihaoyi/mill/blob/0.10.3/scalajslib/src/ScalaJSModule.scala
// TODO: move this to a non-deprecated API when possible.
// the point is to give us a `fastestOpt` target that uses no optimization,
// even when it's set to true in the module.
private def linkTaskCustom(mode: OptimizeMode): Task[PathRef] = T.task {
link(
worker = ScalaJSWorkerApi.scalaJSWorker(),
toolsClasspath = scalaJSToolsClasspath(),
runClasspath = runClasspath(),
mainClass = finalMainClassOpt().toOption,
testBridgeInit = false,
mode = mode,
moduleKind = moduleKind(),
esFeatures = esFeatures()
)
}
def fastestOpt: Target[PathRef] = T {
linkTaskCustom(mode = FastOpt)()
}
override def ivyDeps =
super.ivyDeps() ++
Agg(
ivy"org.julianmichael::jjm-ui::$jjmVersion",
ivy"com.github.japgolly.scalacss::core::$scalacssVersion",
ivy"com.github.japgolly.scalacss::ext-react::$scalacssVersion",
ivy"org.scala-js::scalajs-dom::$scalajsDomVersion",
ivy"be.doeraene::scalajs-jquery::$scalajsJqueryVersion",
ivy"org.scala-js::scala-js-macrotask-executor::$scalajsMacrotaskExecutorVersion"
)
def jsDeps = Agg(
s"https://code.jquery.com/jquery-$jqueryVersion.min.js",
s"https://unpkg.com/react@$reactVersion/umd/react.development.js",
s"https://unpkg.com/react-dom@$reactVersion/umd/react-dom.development.js",
s"https://cdn.jsdelivr.net/npm/vega@$vegaVersion",
s"https://cdn.jsdelivr.net/npm/vega-lite@$vegaLiteVersion",
s"https://cdn.jsdelivr.net/npm/vega-embed@$vegaEmbedVersion"
)
// object test extends super.Tests with CommonTestModule {
// def moduleDeps = Seq(debate.js)
// def platformSegment = "js"
// def scalaJSVersion = T(thisScalaJSVersion)
// def moduleKind = T(ModuleKind.ESModule)
// }
}
object dev extends Module {
def serve(args: String*) = T.command {
val runMain = jvm.runMainFn()
runMain(
"debate.Serve",
Seq(
"--js",
js.fastestOpt().path.toString,
"--jsDeps",
js.aggregatedJSDeps().path.toString
) ++ args
)
}
}
object prod extends Module {
def serve(args: String*) = T.command {
val runMain = jvm.runMainFn()
runMain(
"debate.Serve",
Seq("--js", js.fullOpt().path.toString, "--jsDeps", js.aggregatedJSDeps().path.toString) ++
args
)
}
}
}