build.sc
author Tomas Zeman <tzeman@volny.cz>
Thu, 03 Jan 2019 13:32:19 +0100
changeset 25 da897e7419e7
parent 24 c9b64d8025ed
child 26 4978df5ebf0a
permissions -rw-r--r--
Added tag 18.12 for changeset c9b64d8025ed

import ammonite.ops._
import mill._
import mill.define.{Input, Sources, Target}
import mill.scalajslib._
import mill.scalalib._
import mill.scalalib.publish._
import mill.util.Loose

val appVersion = "18.12"

val scalaJsVer = "0.6.25"
val scalaVer = "2.12.7"
val akkaVer = "2.4.20"

trait Common extends ScalaModule with PublishModule {
  val scalaVersion = scalaVer

  def publishVersion: Target[String] = appVersion

  def pomSettings = PomSettings(
    description = "Content management system for SQWL",
    organization = "net.tz",
    url = "http://kvalitapracovnihozivota.vubp.cz",
    licenses = Seq(License.`Apache-2.0`),
    versionControl = VersionControl(developerConnection = Some(
      "ssh://hg@bitbucket.org/tzeman/sqwl-cms")),
    developers = Seq(
      Developer("tzeman", "Tomas Zeman", "")
    )
  )

  override def artifactName = T{
    super.artifactName.map(_.flatMap(c =>
      if (c.isUpper) Seq('-', c.toLower) else Seq(c) ))
  }

  override def scalacOptions = T{Seq(
    "-deprecation",                      // Emit warning and location for usages of deprecated APIs.
    "-encoding", "utf-8",                // Specify character encoding used by source files.
    "-explaintypes",                     // Explain type errors in more detail.
    "-feature",                          // Emit warning and location for usages of features that should be imported explicitly.
    "-language:higherKinds",             // Allow higher-kinded types
    "-language:implicitConversions",     // Allow definition of implicit functions called views
    "-language:reflectiveCalls",
    "-language:postfixOps",
    "-unchecked",                        // Enable additional warnings where generated code depends on assumptions.
    "-Xcheckinit",                       // Wrap field accessors to throw an exception on uninitialized access.
    "-Xfuture",                          // Turn on future language features.
    "-target:jvm-1.8",
  )}

  def hgId: Input[String] = T.input {
    os.proc("hg", "id", "-i").call().out.string.trim
  }
}

trait Versions {
  //val bootstrap = "4.1.3"
  val bootstrap = "3.3.7"
  val fontAwesome = "5.5.0"
  val jquery = "3.3.1-1"
}

object base extends Common with Versions {
  override def scalacPluginIvyDeps: Target[Loose.Agg[Dep]] =
    super.scalacPluginIvyDeps() ++ Agg(
      ivy"org.scalamacros:::paradise:2.1.0"
    )

  override def ivyDeps = Agg(
    ivy"com.wacai::config-annotation:0.3.6",
    ivy"de.heikoseeberger::akka-http-json4s:1.22.0",
    ivy"com.typesafe.akka::akka-slf4j:$akkaVer",
    ivy"org.json4s::json4s-native:3.6.2",
    ivy"ch.qos.logback:logback-classic:1.2.3",
    ivy"com.lihaoyi::scalatags:0.6.7",
    ivy"org.webjars:bootstrap:$bootstrap",
    ivy"org.webjars:font-awesome:$fontAwesome",
    ivy"org.webjars:jquery:$jquery",
    ivy"com.lihaoyi::scalatex-api:0.3.12"
  )

  override def scalacOptions = T{super.scalacOptions.map(_ :+
    "-Xmacro-settings:conf.output.dir=base/resources"
  )}

  override def generatedSources: Target[Seq[PathRef]] = T{
    val dir = T.ctx().dest
    write(dir / "buildInfo.scala",
      s"""
        | package sqwl.cms
        | object BuildInfo {
        |   object versions {
        |     val bootstrap = "$bootstrap"
        |     val fontAwesome = "$fontAwesome"
        |     val jquery = "$jquery"
        |   }
        |
        |   val hgId = "${hgId()}"
        | }
      """.stripMargin)
    Seq(PathRef(dir))
  }

}

trait Content extends Common {

  override def moduleDeps = Seq(base)

  def contentSources: Sources

  override def generatedSources: Target[Seq[PathRef]] = T{
    val dir = T.ctx().dest
    val src = contentSources() map(_.path)
    val ids = src flatMap(ls! _ filter(_.name endsWith ".scalatex") map { p =>
      val id = p.name replaceAllLiterally (".scalatex", "")
      val aid = s"article-$id"
      write(dir / s"$id.scala",
        s"""
          | package sqwl.cms
          | import scalatags.Text.all._
          | import scalatex._
          | import sqwl.cms.Category._
          | import sqwl.cms.Tag._
          | import sqwl.cms.Articles.article
          | object `$aid` {
          |   implicit val id = Articles.Id("$id")
          |   twf("${p.toString}")
          | }
          |
          |/*
          |${os.read(p).lines mkString "\n"}
          |*/
        """.stripMargin)
      aid
    })

    write(dir / "initializer.scala",
      s"""
        | package sqwl.cms
        | object InitializeContent {
        |   def apply(): Unit = {
        |     Seq(${ids mkString("`", "`, `", "`")})
        |   }
        | }
      """.stripMargin)

    write(dir / "main.scala",
      """
        | package sqwl.cms
        | object Main extends Server {
        |   override def content: iContent = Content
        | }
      """.stripMargin)

    Seq(PathRef(dir))
  }

  override def mainClass = Some("sqwl.cms.Main")

  override def ivyDeps = Agg(
    ivy"com.beachape::enumeratum:1.5.13"
  )
}

object example extends Content {
  def contentSources: Sources =
    T.sources{ millSourcePath / up / 'example / 'content }
}

object production extends Content {
  def contentSources: Sources =
    T.sources{ millSourcePath / up / 'production / 'content }
}


object js extends Common with ScalaJSModule {
  def scalaJSVersion: Target[String] = scalaJsVer
}

// vim: et ts=2 sw=2 syn=scala