/
build.sbt
81 lines (60 loc) · 2.19 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
organization := "io.github.scala-ts"
name := "sbt-plugin-test-custom-cfg"
version := "1.0-SNAPSHOT"
enablePlugins(ScalatsGeneratorPlugin) // Required as disabled by default
// Custom option transpiling
scalatsOptionToNullable := true
// TODO: cross example with custom class in separate module
// Custom type naming (defined in `project/CustomTypeNaming.scala`)
scalatsTypeNaming := classOf[scalats.CustomTypeNaming]
// Custom field naming (defined in `project/CustomFieldMapper.scala`)
scalatsFieldMapper := classOf[scalats.CustomFieldMapper]
// Overwrite the directory the printer is initialized with
scalatsOnCompile / sourceManaged := {
val dir = target.value / "_custom"
dir.mkdirs()
dir
}
// Custom printer (defined in `project/CustomPrinter.scala`)
scalatsPrinter := scalatsPrinterForClass[scalats.CustomPrinter]()
scalatsPrinterPrelude := scalatsPrinterInMemoryPrelude(
"import { Option } from 'space-monad'",
"export const _notUsed = [Option]",
"// could be useful to import common types"
)
// Custom declaration mapper (before type mapper)
scalatsDeclarationMappers := Seq(
scalatsEnumerationAsEnum,
scalatsValueClassAsTagged,
classOf[scalats.CustomDeclarationMapper]
// defined in `project/CustomDeclarationMapper.scala`
)
// Custom type mapper
scalatsTypeMappers := Seq(
scalatsNullableAsOption, // Also scalatsDateAsString, scalatsNumberAsString
classOf[scalats.CustomTypeMapper]
// defined in `project/CustomTypeMapper.scala`
)
// Distribute src/test/typescript as ts-test
Compile / compile := {
val res = (Compile / compile).value
val src = (Test / sourceDirectory).value / "typescript"
val dest = (scalatsOnCompile / sourceManaged).value / "ts-test"
sbt.io.IO.copyDirectory(src, dest, overwrite = true)
res
}
TaskKey[Unit]("preserveGeneratedTypescript") := {
import sbt.io.IO
val logger = streams.value.log
sys.props.get("scala-ts.sbt-test-temp") match {
case Some(path) => {
val tmpdir = new File(path)
tmpdir.mkdirs()
val destdir = tmpdir / name.value / "target"
destdir.mkdirs()
logger.info(s"Copying directory ${target.value} to ${destdir} ...")
IO.copyDirectory(target.value, destdir)
}
case _ => ()
}
}