This repository has been archived by the owner on Jan 13, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathzio_module.sc
145 lines (111 loc) · 4.47 KB
/
zio_module.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
// format: off
import $ivy.`com.goyeau::mill-scalafix::0.2.8`
import com.goyeau.mill.scalafix.ScalafixModule
import $file.cross
import cross.Cross._
// format: on
import mill._
import mill.define.Sources
import mill.define.Target
import mill.modules.Jvm
import mill.scalajslib.ScalaJSModule
import mill.scalalib._
// Scalafix and Scala Format
import mill.scalalib.scalafmt.ScalafmtModule
import os.Path
trait ZIOModule extends SbtModule with ScalafmtModule with ScalafixModule { outer =>
def projectRoot: Path
def deps: Deps
def scalafixScalaBinaryVersion = T {
deps.prjScalaVersion match {
case PrjScalaVersion.Scala_2_13 => "2.13"
case PrjScalaVersion.Scala_3_1_0 => "3"
}
}
def moduleName = millModuleSegments.parts.filterNot(_.equals(deps.prjScalaVersion.version)).mkString("-")
override def millSourcePath = projectRoot / moduleName
override def artifactName: T[String] = T(moduleName)
def extraSources: Seq[String] = deps.prjScalaVersion match {
case PrjScalaVersion.Scala_2_13 => Seq("2.13")
case PrjScalaVersion.Scala_3_1_0 => Seq("3.x")
}
def createSourcePaths(prjKind: PrjKind, scope: String, extra: Seq[String]): Seq[PathRef] =
(Seq("scala") ++ extra.map(e => s"scala-$e")).flatMap(ep =>
Seq(
PathRef(millSourcePath / prjKind.kind / "src" / scope / ep),
PathRef(millSourcePath / "shared" / "src" / scope / ep)
)
)
override def sources: Sources = T.sources(createSourcePaths(PrjKind.JvmProject, "main", extraSources))
private val silencerVersion = "1.7.7"
private lazy val silencerLib = s"com.github.ghik:::silencer-lib:$silencerVersion"
override def scalacOptions = T {
val fatalWarnings: Seq[String] =
if (sys.env.contains("CI")) {
Seq("-Werror")
} else {
Seq.empty
}
val stdOptions: Seq[String] = Seq(
"-deprecation",
"-encoding",
"UTF-8"
) ++ fatalWarnings
deps.prjScalaVersion match {
case PrjScalaVersion.Scala_2_13 =>
stdOptions ++
Seq(
"-feature",
"-language:higherKinds",
"-language:existentials",
"-unchecked",
"-Ywarn-unused",
"-Wunused:imports",
"-Wunused:patvars",
"-Wunused:privates",
"-Wvalue-discard",
"-Xsource:3"
)
case PrjScalaVersion.Scala_3_1_0 =>
stdOptions
}
}
override def scalacPluginIvyDeps =
T {
val libs: Agg[Dep] = deps.prjScalaVersion match {
case PrjScalaVersion.Scala_2_13 => Agg(ivy"$silencerLib")
case _ => Agg.empty[Dep]
}
super.scalacPluginIvyDeps() ++ libs
}
override def ivyDeps =
T {
val libs: Agg[Dep] = deps.prjScalaVersion match {
case PrjScalaVersion.Scala_2_13 => Agg(ivy"$silencerLib")
case _ => Agg.empty[Dep]
}
super.ivyDeps() ++ libs ++ Agg(deps.zio)
}
trait Tests extends super.Tests with ScalafmtModule with ScalafixModule {
override def scalaVersion = outer.scalaVersion
override def scalafixScalaBinaryVersion = outer.scalafixScalaBinaryVersion
override def artifactName = T(outer.artifactName() + "-test")
override def testFramework: T[String] = T("zio.test.sbt.ZTestFramework")
override def ivyDeps = T(outer.ivyDeps() ++ Agg(deps.zioTest, deps.zioTestSbt))
override def sources: Sources = T.sources(outer.createSourcePaths(PrjKind.JvmProject, "test", outer.extraSources))
}
trait JSModule extends SbtModule with ScalafmtModule with ScalafixModule with ScalaJSModule { outerJS =>
override def scalaVersion: T[String] = outer.scalaVersion
override def scalaJSVersion: T[String] = T(outer.deps.scalaJSVersion)
override def artifactName = T(outer.moduleName + "-js")
override def sources: Sources = T.sources(outer.createSourcePaths(PrjKind.JsProject, "main", outer.extraSources))
override def ivyDeps = outer.ivyDeps
trait Tests extends outer.Tests with ScalaJSModule {
override def scalaJSVersion: Target[String] = outerJS.scalaJSVersion
override def artifactName = T(outerJS.artifactName() + "-test")
override def testFramework: T[String] = T("zio.test.sbt.ZTestFramework")
override def sources: Sources = T.sources(outer.createSourcePaths(PrjKind.JsProject, "test", outer.extraSources))
override def ivyDeps = T(outerJS.ivyDeps() ++ Agg(deps.zioTest, deps.zioTestSbt))
}
}
} /* end ZIOModule */