-
Notifications
You must be signed in to change notification settings - Fork 11
/
build.sbt
388 lines (354 loc) · 11.7 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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
import java.nio.file.Files
import java.nio.file.StandardCopyOption.REPLACE_EXISTING
import org.scalajs.jsenv.nodejs.NodeJSEnv
import scala.sys.process.Process
onLoad in Global := {
println(
"""*
|* Welcome to ScalablyTyped demos!
|*
|* For documentation see https://scalablytyped.org .
|*
|* Note that the first time you import/compile the projects it'll take a while for the dependencies to build
|*""".stripMargin
)
(onLoad in Global).value
}
Global / stRemoteCache := RemoteCache.S3Aws(
bucket = "scalablytyped-demos",
region = "eu-central-1",
prefix = Some("st-cache")
)
/**
* Custom task to start demo with webpack-dev-server, use as `<project>/start`.
* Just `start` also works, and starts all frontend demos
*
* After that, the incantation is this to watch and compile on change:
* `~<project>/fastOptJS::webpack`
*/
lazy val start = TaskKey[Unit]("start")
/** Say just `dist` or `<project>/dist` to make a production bundle in
* `docs` for github publishing
*/
lazy val dist = TaskKey[File]("dist")
lazy val vue =
project
.enablePlugins(ScalablyTypedConverterPlugin)
.configure(baseSettings, bundlerSettings, browserProject)
.settings(
Compile / npmDependencies ++= Seq("vue" -> "2.6.11"),
useYarn := true,
webpackDevServerPort := 8004
)
lazy val three =
project
.enablePlugins(ScalablyTypedConverterPlugin)
.configure(baseSettings, bundlerSettings, browserProject, withCssLoading)
.settings(
Compile / npmDependencies ++= Seq("three" -> "0.112.1"),
stUseScalaJsDom := false,
webpackDevServerPort := 8005,
useYarn := true
)
lazy val d3 = project
.enablePlugins(ScalablyTypedConverterPlugin)
.configure(baseSettings, bundlerSettings, browserProject)
.settings(
Compile / npmDependencies ++= Seq(
"d3" -> "5.15",
"@types/d3" -> "5.7.2"
),
/* we use a bit of functionality which can't be found in scala-js-dom */
stUseScalaJsDom := false,
useYarn := true,
webpackDevServerPort := 8001
)
lazy val jquery = project
.enablePlugins(ScalablyTypedConverterPlugin)
.configure(baseSettings, bundlerSettings, browserProject, withCssLoading)
.settings(
Compile / npmDependencies ++= Seq(
"jquery" -> "3.3",
"@types/jquery" -> "3.3.31",
"jqueryui" -> "1.11.1",
"@types/jqueryui" -> "1.12.10"
),
useYarn := true,
webpackDevServerPort := 8003
)
lazy val `google-maps` = project
.enablePlugins(ScalablyTypedConverterPlugin)
.configure(baseSettings, bundlerSettings, browserProject)
.settings(
Compile / npmDependencies ++= Seq(
"@types/googlemaps" -> "3.39.2"
),
webpackDevServerPort := 8002,
useYarn := true
)
lazy val reveal = project
.enablePlugins(ScalablyTypedConverterPlugin)
.configure(baseSettings, bundlerSettings, browserProject, withCssLoading)
.settings(
Compile / npmDependencies ++= Seq(
"@types/highlight.js" -> "9.12.3",
"@types/reveal" -> "3.3.33",
"highlight.js" -> "9.12",
"reveal.js" -> "3.7.0",
"react" -> "16.9",
"react-dom" -> "16.9"
),
// note: this demo is not a react demo. It doesn't use any typescript react components, it's just used to render
stIgnore ++= List("react", "react-dom", "reveal.js"),
stFlavour := Flavour.ScalajsReact,
useYarn := true,
webpackDevServerPort := 8006
)
lazy val chart = project
.enablePlugins(ScalablyTypedConverterPlugin)
.configure(baseSettings, bundlerSettings, browserProject)
.settings(
Compile / npmDependencies ++= Seq(
"@types/chart.js" -> "2.9.11",
"chart.js" -> "2.9.3"
),
stUseScalaJsDom := false,
useYarn := true,
webpackDevServerPort := 8007
)
lazy val p5 = project
.enablePlugins(ScalablyTypedConverterPlugin)
.configure(baseSettings, bundlerSettings, browserProject)
.settings(
Compile / npmDependencies ++= Seq(
"@types/p5" -> "0.9.0",
"p5" -> "0.9"
),
useYarn := true,
webpackDevServerPort := 8009
)
lazy val leaflet = project
.enablePlugins(ScalablyTypedConverterPlugin)
.configure(baseSettings, bundlerSettings, browserProject)
.settings(
Compile / npmDependencies ++= Seq(
"leaflet" -> "1.9.2",
"@types/leaflet" -> "1.9.0"
),
useYarn := true,
webpackDevServerPort := 8010
)
lazy val angular = project
.enablePlugins(ScalablyTypedConverterPlugin)
.configure(baseSettings, bundlerSettings, browserProject, withCssLoading)
.settings(
Compile / npmDependencies ++= Seq(
"@angular/common" -> "8.2.14",
"@angular/compiler" -> "8.2.14",
"@angular/core" -> "8.2.14",
"@angular/forms" -> "8.2.14",
"@angular/platform-browser-dynamic" -> "8.2.14",
"@angular/platform-browser" -> "8.2.14",
"@angular/router" -> "8.2.14",
"core-js" -> "2.6.8",
"rxjs" -> "6.5.4",
"tslib" -> "1.10.0",
"zone.js" -> "0.9.1"
),
stEnableScalaJsDefined := Selection.NoneExcept("@angular/core"),
stIgnore := List(
/* this shouldn't be used directly */
"@angular/compiler",
/* not very interesting */
"core-js"
),
useYarn := true,
webpackDevServerPort := 8008
)
lazy val onsenui =
project
.enablePlugins(ScalablyTypedConverterPlugin)
.configure(baseSettings, bundlerSettings, browserProject)
.settings(
Compile / npmDependencies ++= Seq(
"@types/jquery" -> "3.3.31",
"jquery" -> "3.3",
"onsenui" -> "2.10.10"
),
useYarn := true,
webpackDevServerPort := 8011
)
lazy val phaser =
project
.enablePlugins(ScalablyTypedConverterPlugin)
.configure(baseSettings, bundlerSettings, browserProject, withCssLoading)
.settings(
Compile / npmDependencies ++= Seq("phaser" -> "3.22.0"),
useYarn := true,
webpackDevServerPort := 8012
)
lazy val pixi = project
.enablePlugins(ScalablyTypedConverterPlugin)
.configure(baseSettings, bundlerSettings, browserProject, withCssLoading)
.settings(
Compile / npmDependencies ++= Seq(
"pixi.js" -> "5.2.1",
"pixi-filters" -> "3.1.0",
"@types/highlight.js" -> "9.12.3",
"highlight.js" -> "9.12"
),
useYarn := true,
webpackDevServerPort := 8013
)
lazy val cypress = project
.enablePlugins(ScalablyTypedConverterPlugin)
.configure(baseSettings, bundlerSettings)
.settings(
Compile / npmDependencies ++= Seq(
"cypress" -> "8.5.0",
),
useYarn := true,
run := {
(Compile / npmInstallDependencies).value
(Compile / fastOptJS).value
val cypressRunner: File = (Compile / npmUpdate / crossTarget).value / "node_modules" / ".bin" / "cypress"
if (Process(s"$cypressRunner run", baseDirectory.value).run().exitValue() != 0) throw new RuntimeException("failed")
}
)
lazy val electron = project
.enablePlugins(ScalablyTypedConverterExternalNpmPlugin)
.configure(baseSettings)
.settings(
stStdlib := List("es5"), // doesn't include DOM
/**
* ScalablyTypedConverterExternalNpmPlugin requires that we define how to install node dependencies and where they are
*
* Since we run yarn ourselves the dependencies live in electron/package.json
*
* Invoking yarn is somewhat awkward, because for instance sbt started through intellij won't have a proper PATH set.
* try to start an interactive shell to read the necessary dot files
*/
externalNpm := {
if (scala.util.Properties.isWin) Process("yarn", baseDirectory.value).run()
else Process("bash -ci 'yarn'", baseDirectory.value).run()
baseDirectory.value
},
jsEnv := new NodeJSEnv(
NodeJSEnv
.Config()
.withExecutable("electron/node_modules/.bin/electron")
.withArgs(List((Compile / classDirectory).value.toString))
)
)
lazy val lodash =
project
.enablePlugins(ScalablyTypedConverterPlugin)
.configure(baseSettings, bundlerSettings, nodeProject)
.settings(
Compile / npmDependencies ++= Seq(
"@types/lodash" -> "4.14.149",
"lodash" -> "4.17.11"
),
useYarn := true
)
lazy val `node-express` =
project
.enablePlugins(ScalablyTypedConverterPlugin)
.configure(baseSettings, bundlerSettings, nodeProject)
.settings(
Compile / npmDependencies ++= Seq(
"@types/express" -> "4.17.14",
"express" -> "4.18.2"
),
useYarn := true
)
lazy val typescript =
project
.enablePlugins(ScalablyTypedConverterPlugin)
.configure(baseSettings, bundlerSettings, nodeProject)
.settings(
Compile / npmDependencies ++= Seq(
"typescript" -> "3.8.3"
),
/* typescript is implicitly added by the plugin since that's where we get the files for stdlib, and also implicitly ignored */
stIgnore ~= (_.filterNot(_ == "typescript")),
useYarn := true
)
lazy val baseSettings: Project => Project =
_.enablePlugins(ScalaJSPlugin)
.settings(
scalaVersion := "3.3.0",
version := "0.1-SNAPSHOT",
scalacOptions ++= Seq("-deprecation", "-feature", "-unchecked"),
scalaJSUseMainModuleInitializer := true,
scalaJSLinkerConfig ~= (_
/* disabled because it somehow triggers many warnings */
.withSourceMap(false)
.withModuleKind(ModuleKind.CommonJSModule))
)
lazy val bundlerSettings: Project => Project =
_.settings(
webpackCliVersion := "4.10.0",
webpack / version := "5.88.2",
Compile / fastOptJS / webpackExtraArgs += "--mode=development",
Compile / fullOptJS / webpackExtraArgs += "--mode=production",
Compile / fastOptJS / webpackDevServerExtraArgs += "--mode=development",
Compile / fullOptJS / webpackDevServerExtraArgs += "--mode=production"
)
val nodeProject: Project => Project =
_.settings(
jsEnv := new org.scalajs.jsenv.nodejs.NodeJSEnv,
// this doesn't include DOM, which we don't have access to in node. It does, however use BigInt, which is needed
stStdlib := List("esnext"),
stUseScalaJsDom := false,
Compile / npmDependencies ++= Seq(
"@types/node" -> "18.11.9"
)
)
lazy val withCssLoading: Project => Project =
_.settings(
/* custom webpack file to include css */
webpackConfigFile := Some((ThisBuild / baseDirectory).value / "custom.webpack.config.js"),
Compile / npmDevDependencies ++= Seq(
"webpack-merge" -> "5.9.0",
"css-loader" -> "6.8.1",
"style-loader" -> "3.3.3",
"file-loader" -> "6.2.0",
"url-loader" -> "4.1.1"
)
)
/**
* Implement the `start` and `dist` tasks defined above.
* Most of this is really just to copy the index.html file around.
*/
lazy val browserProject: Project => Project =
_.settings(
start := {
(Compile / fastOptJS / startWebpackDevServer).value
},
dist := {
val artifacts = (Compile / fullOptJS / webpack).value
val artifactFolder = (Compile / fullOptJS / crossTarget).value
val distFolder = (ThisBuild / baseDirectory).value / "docs" / moduleName.value
distFolder.mkdirs()
artifacts.foreach { artifact =>
val target = artifact.data.relativeTo(artifactFolder) match {
case None => distFolder / artifact.data.name
case Some(relFile) => distFolder / relFile.toString
}
Files.copy(artifact.data.toPath, target.toPath, REPLACE_EXISTING)
}
val indexFrom = baseDirectory.value / "src/main/js/index.html"
val indexTo = distFolder / "index.html"
val indexPatchedContent = {
import collection.JavaConverters._
Files
.readAllLines(indexFrom.toPath, IO.utf8)
.asScala
.map(_.replaceAllLiterally("-fastopt-", "-opt-"))
.mkString("\n")
}
Files.write(indexTo.toPath, indexPatchedContent.getBytes(IO.utf8))
distFolder
}
)