| author | Tomas Zeman <tzeman@volny.cz> |
| Thu, 17 Jan 2019 18:26:38 +0100 | |
| changeset 22 | 35f19c3873e2 |
| parent 21 | 175e7d7ce5b3 |
| child 24 | 782f121133c7 |
| permissions | -rw-r--r-- |
| 20 | 1 |
import ammonite.ops._ |
2 |
import mill._ |
|
3 |
import mill.define.{Input, Sources, Target}
|
|
4 |
import mill.scalajslib._ |
|
5 |
import mill.scalalib._ |
|
6 |
import mill.scalalib.publish._ |
|
7 |
import mill.util.Loose |
|
8 |
||
9 |
object V {
|
|
| 22 | 10 |
val fatags = "0.4" |
| 20 | 11 |
val scalaJs = "0.6.26" |
12 |
val scala211 = "2.11.12" |
|
13 |
val scala212 = "2.12.8" |
|
14 |
} |
|
15 |
||
16 |
object D {
|
|
17 |
val scalatags = ivy"com.lihaoyi::scalatags::0.6.7" |
|
18 |
} |
|
19 |
||
20 |
trait Common extends CrossSbtModule with PublishModule {
|
|
21 |
||
22 |
def publishVersion: Target[String] = V.fatags |
|
23 |
||
24 |
def pomSettings = PomSettings( |
|
25 |
description = "FontAwesome Scala DSL (tags)", |
|
26 |
organization = "net.tz", |
|
27 |
url = "https://bitbucket.org/tzeman/fatags", |
|
28 |
licenses = Seq(License.`Apache-2.0`), |
|
29 |
versionControl = VersionControl(developerConnection = Some( |
|
30 |
"ssh://hg@bitbucket.org/tzeman/fatags")), |
|
31 |
developers = Seq( |
|
32 |
Developer("tzeman", "Tomas Zeman", "")
|
|
33 |
) |
|
34 |
) |
|
35 |
||
36 |
override def scalacOptions = T{Seq(
|
|
37 |
"-deprecation", // Emit warning and location for usages of deprecated APIs. |
|
38 |
"-encoding", "utf-8", // Specify character encoding used by source files. |
|
39 |
"-explaintypes", // Explain type errors in more detail. |
|
40 |
"-feature", // Emit warning and location for usages of features that should be imported explicitly. |
|
41 |
"-language:higherKinds", // Allow higher-kinded types |
|
42 |
"-language:implicitConversions", // Allow definition of implicit functions called views |
|
43 |
"-language:reflectiveCalls", |
|
44 |
"-language:postfixOps", |
|
45 |
"-unchecked", // Enable additional warnings where generated code depends on assumptions. |
|
46 |
"-Xcheckinit", // Wrap field accessors to throw an exception on uninitialized access. |
|
47 |
"-Xfuture", // Turn on future language features. |
|
48 |
"-target:jvm-1.8", |
|
49 |
)} |
|
50 |
||
51 |
def hgId: Input[String] = T.input {
|
|
52 |
os.proc("hg", "id", "-i").call().out.string.trim
|
|
53 |
} |
|
54 |
||
55 |
def hgNum: Input[String] = T.input {
|
|
56 |
os.proc("hg", "id", "-n").call().out.string.trim
|
|
57 |
} |
|
58 |
||
59 |
def hgTag: Input[Option[String]] = T.input {
|
|
60 |
os.proc("hg", "id", "-t").call().out.string.trim.split(' ').headOption
|
|
61 |
} |
|
62 |
||
63 |
override def ivyDeps: Target[Loose.Agg[Dep]] = Agg(D.scalatags) |
|
64 |
||
65 |
override def sources: Sources = T.sources{
|
|
66 |
super.sources() :+ PathRef(millSourcePath / 'shared / 'src / 'main / 'scala) |
|
67 |
} |
|
68 |
||
|
21
175e7d7ce5b3
Font-Awesome upgrade 4.7 -> 5.6.3
Tomas Zeman <tzeman@volny.cz>
parents:
20
diff
changeset
|
69 |
// https://github.com/FortAwesome/Font-Awesome/raw/5.6.3/metadata/icons.json |
|
175e7d7ce5b3
Font-Awesome upgrade 4.7 -> 5.6.3
Tomas Zeman <tzeman@volny.cz>
parents:
20
diff
changeset
|
70 |
type IcoDef = (String, Set[String]) |
|
175e7d7ce5b3
Font-Awesome upgrade 4.7 -> 5.6.3
Tomas Zeman <tzeman@volny.cz>
parents:
20
diff
changeset
|
71 |
def parseIcons: Target[List[IcoDef]] = T{
|
|
175e7d7ce5b3
Font-Awesome upgrade 4.7 -> 5.6.3
Tomas Zeman <tzeman@volny.cz>
parents:
20
diff
changeset
|
72 |
ujson.read(os.read! pwd / "icons.json").obj.map(e => (e._1, e._2.obj("styles").arr.map(_.str).toSet)).toList
|
|
175e7d7ce5b3
Font-Awesome upgrade 4.7 -> 5.6.3
Tomas Zeman <tzeman@volny.cz>
parents:
20
diff
changeset
|
73 |
} |
|
175e7d7ce5b3
Font-Awesome upgrade 4.7 -> 5.6.3
Tomas Zeman <tzeman@volny.cz>
parents:
20
diff
changeset
|
74 |
|
|
175e7d7ce5b3
Font-Awesome upgrade 4.7 -> 5.6.3
Tomas Zeman <tzeman@volny.cz>
parents:
20
diff
changeset
|
75 |
private def tpl(d: IcoDef): String = {
|
|
175e7d7ce5b3
Font-Awesome upgrade 4.7 -> 5.6.3
Tomas Zeman <tzeman@volny.cz>
parents:
20
diff
changeset
|
76 |
val sym = d._1 match {
|
|
175e7d7ce5b3
Font-Awesome upgrade 4.7 -> 5.6.3
Tomas Zeman <tzeman@volny.cz>
parents:
20
diff
changeset
|
77 |
//case "clone" => "clone_" |
|
175e7d7ce5b3
Font-Awesome upgrade 4.7 -> 5.6.3
Tomas Zeman <tzeman@volny.cz>
parents:
20
diff
changeset
|
78 |
case x => x |
|
175e7d7ce5b3
Font-Awesome upgrade 4.7 -> 5.6.3
Tomas Zeman <tzeman@volny.cz>
parents:
20
diff
changeset
|
79 |
} |
|
175e7d7ce5b3
Font-Awesome upgrade 4.7 -> 5.6.3
Tomas Zeman <tzeman@volny.cz>
parents:
20
diff
changeset
|
80 |
d._2.map {
|
|
175e7d7ce5b3
Font-Awesome upgrade 4.7 -> 5.6.3
Tomas Zeman <tzeman@volny.cz>
parents:
20
diff
changeset
|
81 |
case "brands" => s""" val `fab-$sym`: T = fab("${d._1}")\n"""
|
|
175e7d7ce5b3
Font-Awesome upgrade 4.7 -> 5.6.3
Tomas Zeman <tzeman@volny.cz>
parents:
20
diff
changeset
|
82 |
case "solid" => s""" val `fas-$sym`: T = fas("${d._1}")\n"""
|
|
175e7d7ce5b3
Font-Awesome upgrade 4.7 -> 5.6.3
Tomas Zeman <tzeman@volny.cz>
parents:
20
diff
changeset
|
83 |
case "regular" => s""" val `far-$sym`: T = far("${d._1}")\n"""
|
|
175e7d7ce5b3
Font-Awesome upgrade 4.7 -> 5.6.3
Tomas Zeman <tzeman@volny.cz>
parents:
20
diff
changeset
|
84 |
}.mkString |
|
175e7d7ce5b3
Font-Awesome upgrade 4.7 -> 5.6.3
Tomas Zeman <tzeman@volny.cz>
parents:
20
diff
changeset
|
85 |
} |
|
175e7d7ce5b3
Font-Awesome upgrade 4.7 -> 5.6.3
Tomas Zeman <tzeman@volny.cz>
parents:
20
diff
changeset
|
86 |
|
|
175e7d7ce5b3
Font-Awesome upgrade 4.7 -> 5.6.3
Tomas Zeman <tzeman@volny.cz>
parents:
20
diff
changeset
|
87 |
override def generatedSources: Sources = T.sources{
|
|
175e7d7ce5b3
Font-Awesome upgrade 4.7 -> 5.6.3
Tomas Zeman <tzeman@volny.cz>
parents:
20
diff
changeset
|
88 |
val d = T.ctx().dest |
|
175e7d7ce5b3
Font-Awesome upgrade 4.7 -> 5.6.3
Tomas Zeman <tzeman@volny.cz>
parents:
20
diff
changeset
|
89 |
val icons = parseIcons() |
|
175e7d7ce5b3
Font-Awesome upgrade 4.7 -> 5.6.3
Tomas Zeman <tzeman@volny.cz>
parents:
20
diff
changeset
|
90 |
write(d / "generated.scala", |
|
175e7d7ce5b3
Font-Awesome upgrade 4.7 -> 5.6.3
Tomas Zeman <tzeman@volny.cz>
parents:
20
diff
changeset
|
91 |
s""" |
|
175e7d7ce5b3
Font-Awesome upgrade 4.7 -> 5.6.3
Tomas Zeman <tzeman@volny.cz>
parents:
20
diff
changeset
|
92 |
| package fontawesome.generic |
|
175e7d7ce5b3
Font-Awesome upgrade 4.7 -> 5.6.3
Tomas Zeman <tzeman@volny.cz>
parents:
20
diff
changeset
|
93 |
| import scalatags.generic._ |
|
175e7d7ce5b3
Font-Awesome upgrade 4.7 -> 5.6.3
Tomas Zeman <tzeman@volny.cz>
parents:
20
diff
changeset
|
94 |
| class GenericFA[Builder, Output <: FragT, FragT]( |
|
175e7d7ce5b3
Font-Awesome upgrade 4.7 -> 5.6.3
Tomas Zeman <tzeman@volny.cz>
parents:
20
diff
changeset
|
95 |
| val bun: Bundle[Builder, Output, FragT]) {
|
|
175e7d7ce5b3
Font-Awesome upgrade 4.7 -> 5.6.3
Tomas Zeman <tzeman@volny.cz>
parents:
20
diff
changeset
|
96 |
| |
|
175e7d7ce5b3
Font-Awesome upgrade 4.7 -> 5.6.3
Tomas Zeman <tzeman@volny.cz>
parents:
20
diff
changeset
|
97 |
| import bun.all._ |
|
175e7d7ce5b3
Font-Awesome upgrade 4.7 -> 5.6.3
Tomas Zeman <tzeman@volny.cz>
parents:
20
diff
changeset
|
98 |
| |
|
175e7d7ce5b3
Font-Awesome upgrade 4.7 -> 5.6.3
Tomas Zeman <tzeman@volny.cz>
parents:
20
diff
changeset
|
99 |
| type T = FA[Builder, Output, FragT] |
|
175e7d7ce5b3
Font-Awesome upgrade 4.7 -> 5.6.3
Tomas Zeman <tzeman@volny.cz>
parents:
20
diff
changeset
|
100 |
| |
|
175e7d7ce5b3
Font-Awesome upgrade 4.7 -> 5.6.3
Tomas Zeman <tzeman@volny.cz>
parents:
20
diff
changeset
|
101 |
| val faStack: Modifier = cls := "fa-stack fa-lg" |
|
175e7d7ce5b3
Font-Awesome upgrade 4.7 -> 5.6.3
Tomas Zeman <tzeman@volny.cz>
parents:
20
diff
changeset
|
102 |
| |
|
175e7d7ce5b3
Font-Awesome upgrade 4.7 -> 5.6.3
Tomas Zeman <tzeman@volny.cz>
parents:
20
diff
changeset
|
103 |
| implicit val bundle: Bundle[Builder, Output, FragT] = bun |
|
175e7d7ce5b3
Font-Awesome upgrade 4.7 -> 5.6.3
Tomas Zeman <tzeman@volny.cz>
parents:
20
diff
changeset
|
104 |
| implicit def fa2tag(x: T): TypedTag[Builder, Output, FragT] = x() |
|
175e7d7ce5b3
Font-Awesome upgrade 4.7 -> 5.6.3
Tomas Zeman <tzeman@volny.cz>
parents:
20
diff
changeset
|
105 |
| |
|
175e7d7ce5b3
Font-Awesome upgrade 4.7 -> 5.6.3
Tomas Zeman <tzeman@volny.cz>
parents:
20
diff
changeset
|
106 |
| private def fab(w: String): T = FA(FaStyle.Brands, w) |
|
175e7d7ce5b3
Font-Awesome upgrade 4.7 -> 5.6.3
Tomas Zeman <tzeman@volny.cz>
parents:
20
diff
changeset
|
107 |
| private def far(w: String): T = FA(FaStyle.Regular, w) |
|
175e7d7ce5b3
Font-Awesome upgrade 4.7 -> 5.6.3
Tomas Zeman <tzeman@volny.cz>
parents:
20
diff
changeset
|
108 |
| private def fas(w: String): T = FA(FaStyle.Solid, w) |
|
175e7d7ce5b3
Font-Awesome upgrade 4.7 -> 5.6.3
Tomas Zeman <tzeman@volny.cz>
parents:
20
diff
changeset
|
109 |
| |
|
175e7d7ce5b3
Font-Awesome upgrade 4.7 -> 5.6.3
Tomas Zeman <tzeman@volny.cz>
parents:
20
diff
changeset
|
110 |
| ${icons map(tpl) mkString}
|
|
175e7d7ce5b3
Font-Awesome upgrade 4.7 -> 5.6.3
Tomas Zeman <tzeman@volny.cz>
parents:
20
diff
changeset
|
111 |
| |
|
175e7d7ce5b3
Font-Awesome upgrade 4.7 -> 5.6.3
Tomas Zeman <tzeman@volny.cz>
parents:
20
diff
changeset
|
112 |
| /* |
|
175e7d7ce5b3
Font-Awesome upgrade 4.7 -> 5.6.3
Tomas Zeman <tzeman@volny.cz>
parents:
20
diff
changeset
|
113 |
| object fab {
|
|
175e7d7ce5b3
Font-Awesome upgrade 4.7 -> 5.6.3
Tomas Zeman <tzeman@volny.cz>
parents:
20
diff
changeset
|
114 |
| private def fa(w: String): T = FA(FaStyle.Brands, w) |
|
175e7d7ce5b3
Font-Awesome upgrade 4.7 -> 5.6.3
Tomas Zeman <tzeman@volny.cz>
parents:
20
diff
changeset
|
115 |
| {icons.filter(_._2.contains("brands")).map(tpl).mkString}
|
|
175e7d7ce5b3
Font-Awesome upgrade 4.7 -> 5.6.3
Tomas Zeman <tzeman@volny.cz>
parents:
20
diff
changeset
|
116 |
| } |
|
175e7d7ce5b3
Font-Awesome upgrade 4.7 -> 5.6.3
Tomas Zeman <tzeman@volny.cz>
parents:
20
diff
changeset
|
117 |
| |
|
175e7d7ce5b3
Font-Awesome upgrade 4.7 -> 5.6.3
Tomas Zeman <tzeman@volny.cz>
parents:
20
diff
changeset
|
118 |
| object fas {
|
|
175e7d7ce5b3
Font-Awesome upgrade 4.7 -> 5.6.3
Tomas Zeman <tzeman@volny.cz>
parents:
20
diff
changeset
|
119 |
| private def fa(w: String): T = FA(FaStyle.Solid, w) |
|
175e7d7ce5b3
Font-Awesome upgrade 4.7 -> 5.6.3
Tomas Zeman <tzeman@volny.cz>
parents:
20
diff
changeset
|
120 |
| {icons.filter(_._2.contains("solid")).map(tpl).mkString}
|
|
175e7d7ce5b3
Font-Awesome upgrade 4.7 -> 5.6.3
Tomas Zeman <tzeman@volny.cz>
parents:
20
diff
changeset
|
121 |
| } |
|
175e7d7ce5b3
Font-Awesome upgrade 4.7 -> 5.6.3
Tomas Zeman <tzeman@volny.cz>
parents:
20
diff
changeset
|
122 |
| |
|
175e7d7ce5b3
Font-Awesome upgrade 4.7 -> 5.6.3
Tomas Zeman <tzeman@volny.cz>
parents:
20
diff
changeset
|
123 |
| object far {
|
|
175e7d7ce5b3
Font-Awesome upgrade 4.7 -> 5.6.3
Tomas Zeman <tzeman@volny.cz>
parents:
20
diff
changeset
|
124 |
| private def fa(w: String): T = FA(FaStyle.Regular, w) |
|
175e7d7ce5b3
Font-Awesome upgrade 4.7 -> 5.6.3
Tomas Zeman <tzeman@volny.cz>
parents:
20
diff
changeset
|
125 |
| {icons.filter(_._2.contains("regular")).map(tpl).mkString}
|
|
175e7d7ce5b3
Font-Awesome upgrade 4.7 -> 5.6.3
Tomas Zeman <tzeman@volny.cz>
parents:
20
diff
changeset
|
126 |
| } |
|
175e7d7ce5b3
Font-Awesome upgrade 4.7 -> 5.6.3
Tomas Zeman <tzeman@volny.cz>
parents:
20
diff
changeset
|
127 |
| */ |
|
175e7d7ce5b3
Font-Awesome upgrade 4.7 -> 5.6.3
Tomas Zeman <tzeman@volny.cz>
parents:
20
diff
changeset
|
128 |
| |
|
175e7d7ce5b3
Font-Awesome upgrade 4.7 -> 5.6.3
Tomas Zeman <tzeman@volny.cz>
parents:
20
diff
changeset
|
129 |
| } |
|
175e7d7ce5b3
Font-Awesome upgrade 4.7 -> 5.6.3
Tomas Zeman <tzeman@volny.cz>
parents:
20
diff
changeset
|
130 |
""".stripMargin) |
|
175e7d7ce5b3
Font-Awesome upgrade 4.7 -> 5.6.3
Tomas Zeman <tzeman@volny.cz>
parents:
20
diff
changeset
|
131 |
d |
|
175e7d7ce5b3
Font-Awesome upgrade 4.7 -> 5.6.3
Tomas Zeman <tzeman@volny.cz>
parents:
20
diff
changeset
|
132 |
} |
| 20 | 133 |
} |
134 |
||
135 |
class JvmModule(val crossScalaVersion: String) extends Common |
|
136 |
class JsModule(val crossScalaVersion: String) extends ScalaJSModule |
|
137 |
with Common {
|
|
138 |
override def scalaJSVersion: Target[String] = V.scalaJs |
|
139 |
} |
|
140 |
||
141 |
object jvm extends Cross[JvmModule](V.scala211, V.scala212) |
|
142 |
object js extends Cross[JsModule](V.scala211, V.scala212) |
|
143 |
||
144 |
def publishLocal(): define.Command[Unit] = T.command{
|
|
145 |
jvm(V.scala212).publishLocal()() |
|
146 |
js(V.scala212).publishLocal()() |
|
147 |
jvm(V.scala211).publishLocal()() |
|
148 |
js(V.scala211).publishLocal()() |
|
149 |
} |
|
150 |
||
151 |
object example extends ScalaModule with ScalaJSModule {
|
|
152 |
override def scalaVersion: Target[String] = T{V.scala212}
|
|
153 |
override def scalaJSVersion: Target[String] = V.scalaJs |
|
|
21
175e7d7ce5b3
Font-Awesome upgrade 4.7 -> 5.6.3
Tomas Zeman <tzeman@volny.cz>
parents:
20
diff
changeset
|
154 |
|
|
175e7d7ce5b3
Font-Awesome upgrade 4.7 -> 5.6.3
Tomas Zeman <tzeman@volny.cz>
parents:
20
diff
changeset
|
155 |
|
|
175e7d7ce5b3
Font-Awesome upgrade 4.7 -> 5.6.3
Tomas Zeman <tzeman@volny.cz>
parents:
20
diff
changeset
|
156 |
/* Ugly hack to prevent |
|
175e7d7ce5b3
Font-Awesome upgrade 4.7 -> 5.6.3
Tomas Zeman <tzeman@volny.cz>
parents:
20
diff
changeset
|
157 |
* "Referring to non-existent method fontawesome.generic.FA... error" |
|
175e7d7ce5b3
Font-Awesome upgrade 4.7 -> 5.6.3
Tomas Zeman <tzeman@volny.cz>
parents:
20
diff
changeset
|
158 |
*/ |
|
175e7d7ce5b3
Font-Awesome upgrade 4.7 -> 5.6.3
Tomas Zeman <tzeman@volny.cz>
parents:
20
diff
changeset
|
159 |
//override def moduleDeps: Seq[PublishModule] = Seq(js(V.scala212)) |
|
175e7d7ce5b3
Font-Awesome upgrade 4.7 -> 5.6.3
Tomas Zeman <tzeman@volny.cz>
parents:
20
diff
changeset
|
160 |
override def ivyDeps: Target[Loose.Agg[Dep]] = Agg(D.scalatags) |
|
175e7d7ce5b3
Font-Awesome upgrade 4.7 -> 5.6.3
Tomas Zeman <tzeman@volny.cz>
parents:
20
diff
changeset
|
161 |
override def sources: Sources = T.sources{super.sources() ++ js(V.scala212).sources()}
|
|
175e7d7ce5b3
Font-Awesome upgrade 4.7 -> 5.6.3
Tomas Zeman <tzeman@volny.cz>
parents:
20
diff
changeset
|
162 |
override def generatedSources = T{js(V.scala212).generatedSources()}
|
| 20 | 163 |
} |
164 |
||
|
21
175e7d7ce5b3
Font-Awesome upgrade 4.7 -> 5.6.3
Tomas Zeman <tzeman@volny.cz>
parents:
20
diff
changeset
|
165 |
|
| 20 | 166 |
// vim: et ts=2 sw=2 syn=scala |