build.sc
changeset 25 950431e16cb4
parent 24 782f121133c7
child 26 6ba55bf93ab7
equal deleted inserted replaced
24:782f121133c7 25:950431e16cb4
     3 import mill.define.{Input, Sources, Target}
     3 import mill.define.{Input, Sources, Target}
     4 import mill.scalajslib._
     4 import mill.scalajslib._
     5 import mill.scalalib._
     5 import mill.scalalib._
     6 import mill.scalalib.publish._
     6 import mill.scalalib.publish._
     7 import mill.util.Loose
     7 import mill.util.Loose
       
     8 
       
     9 import scala.language.postfixOps
     8 
    10 
     9 object V {
    11 object V {
    10   val fatags = "0.5-SNAPSHOT"
    12   val fatags = "0.5-SNAPSHOT"
    11   val scalaJs = "0.6.26"
    13   val scalaJs = "0.6.26"
    12   val scala211 = "2.11.12"
    14   val scala211 = "2.11.12"
    13   val scala212 = "2.12.8"
    15   val scala212 = "2.12.8"
    14 }
    16 }
    15 
    17 
    16 object D {
    18 object D {
    17   val scalatags = ivy"com.lihaoyi::scalatags::0.6.7"
    19   val scalatags = ivy"com.lihaoyi::scalatags::0.6.7"
       
    20 }
       
    21 
       
    22 def camelCase(s: String): String = {
       
    23   def inner(l: List[Char]): List[Char] = l match {
       
    24     case '-' :: '-' :: c :: rest => c.toUpper :: inner(rest)
       
    25     case '-' :: c :: rest => c.toUpper :: inner(rest)
       
    26     case c :: rest => c :: inner(rest)
       
    27     case Nil => Nil
       
    28   }
       
    29   inner(s toList) mkString ""
    18 }
    30 }
    19 
    31 
    20 trait Common extends CrossSbtModule with PublishModule {
    32 trait Common extends CrossSbtModule with PublishModule {
    21 
    33 
    22   def publishVersion: Target[String] = V.fatags
    34   def publishVersion: Target[String] = V.fatags
    71   def parseIcons: Target[List[IcoDef]] = T{
    83   def parseIcons: Target[List[IcoDef]] = T{
    72     ujson.read(os.read! pwd / "icons.json").obj.map(e => (e._1, e._2.obj("styles").arr.map(_.str).toSet)).toList
    84     ujson.read(os.read! pwd / "icons.json").obj.map(e => (e._1, e._2.obj("styles").arr.map(_.str).toSet)).toList
    73   }
    85   }
    74 
    86 
    75   private def tpl(d: IcoDef): String = {
    87   private def tpl(d: IcoDef): String = {
    76     val sym = d._1 match {
    88     val sym = d._1
    77       //case "clone" => "clone_"
       
    78       case x => x
       
    79     }
       
    80     d._2.map {
    89     d._2.map {
    81       case "brands" => s"""      val `fab-$sym`: T = fab("${d._1}")\n"""
    90       case "brands" =>  s"""      val ${camelCase(s"fab-$sym")}: T = fab("$sym")\n"""
    82       case "solid" => s"""      val `fas-$sym`: T = fas("${d._1}")\n"""
    91       case "solid" =>   s"""      val ${camelCase(s"fas-$sym")}: T = fas("$sym")\n"""
    83       case "regular" => s"""      val `far-$sym`: T = far("${d._1}")\n"""
    92       case "regular" => s"""      val ${camelCase(s"far-$sym")}: T = far("$sym")\n"""
    84     }.mkString
    93     }.mkString
    85   }
    94   }
    86 
    95 
    87   override def generatedSources: Sources = T.sources{
    96   override def generatedSources: Sources = T.sources{
    88     val d = T.ctx().dest
    97     val d = T.ctx().dest
   105         |
   114         |
   106         |   private def fab(w: String): T = FA(FaStyle.Brands, w)
   115         |   private def fab(w: String): T = FA(FaStyle.Brands, w)
   107         |   private def far(w: String): T = FA(FaStyle.Regular, w)
   116         |   private def far(w: String): T = FA(FaStyle.Regular, w)
   108         |   private def fas(w: String): T = FA(FaStyle.Solid, w)
   117         |   private def fas(w: String): T = FA(FaStyle.Solid, w)
   109         |
   118         |
   110         |   ${icons map(tpl) mkString}
   119         |   ${icons map tpl mkString}
   111         |
       
   112         |   /*
       
   113         |   object fab {
       
   114         |     private def fa(w: String): T = FA(FaStyle.Brands, w)
       
   115         |     {icons.filter(_._2.contains("brands")).map(tpl).mkString}
       
   116         |   }
       
   117         |
       
   118         |   object fas {
       
   119         |     private def fa(w: String): T = FA(FaStyle.Solid, w)
       
   120         |     {icons.filter(_._2.contains("solid")).map(tpl).mkString}
       
   121         |   }
       
   122         |
       
   123         |   object far {
       
   124         |     private def fa(w: String): T = FA(FaStyle.Regular, w)
       
   125         |     {icons.filter(_._2.contains("regular")).map(tpl).mkString}
       
   126         |   }
       
   127         |   */
       
   128         |
   120         |
   129         | }
   121         | }
   130       """.stripMargin)
   122       """.stripMargin)
   131     d
   123     d
   132   }
   124   }