Cells/build.sc

149 lines
3.6 KiB
Scala

import $ivy.`com.lihaoyi::mill-contrib-bloop:$MILL_VERSION`
import $ivy.`io.bit3:jsass:5.10.4`
import mill._
import mill.scalalib._
import mill.scalalib.publish._
import mill.scalajslib._
import coursier.maven.{ MavenRepository }
import mill.util.Ctx
import mill.api.{ Result, PathRef }
import io.bit3.jsass.{ Compiler => SassCompiler, Options => SassOptions, OutputStyle => SassOutputStyle }
/*************************************************
*** Overarching Target
*************************************************/
object cells extends Module {
val scalaVersion = "3.2.1"
def run() = server.run()
object shared extends Module
object server extends ScalaModule
{
def scalaVersion = cells.scalaVersion
def mainClass = Some("net.okennedy.cells.CellsServer")
def ivyDeps = Agg(
ivy"com.lihaoyi::cask:0.8.3",
ivy"com.typesafe.play::play-json::2.10.0-RC7",
)
def sources = T.sources(
millSourcePath,
shared.millSourcePath
)
def resources =
T.sources(
millSourcePath / "shared" / "resources",
cells.resources()
)
}
object ui extends ScalaJSModule
{
def scalaVersion = cells.scalaVersion
def scalaJSVersion = "1.12.0"
def ivyDeps = Agg(
ivy"org.scala-js::scalajs-dom::2.3.0",
ivy"com.raquo::laminar::0.14.5",
ivy"com.typesafe.play::play-json::2.10.0-RC7",
)
def sources = T.sources(
millSourcePath,
shared.millSourcePath
)
def sass =
T.sources {
os.walk(millSourcePath / "css")
.filter { _.ext == "scss" }
.map { PathRef(_) }
}
def compiledSass =
T {
val compiler = new SassCompiler()
val options = new SassOptions()
val target = T.dest
options.setOutputStyle(SassOutputStyle.COMPRESSED)
val src = sass().filter { _.path.last == "cells.scss" }.head
val out = target / "cells.css"
println(s"IGNORE THE FOLLOWING DEPRECATION WARNING: https://gitlab.com/jsass/jsass/-/issues/95")
val output = compiler.compileFile(
new java.net.URI((src.path.toString).toString),
new java.net.URI(out.toString),
options
)
output.getCss
}
def html =
T.sources {
os.walk(millSourcePath / "html")
.map { PathRef(_) }
}
def css =
T.sources {
os.walk(millSourcePath / "css")
.filter { _.ext == "css" }
.map { PathRef(_) }
}
def fonts =
T.sources {
os.walk(millSourcePath / "fonts")
.map { PathRef(_) }
}
}
def resources =
T {
val target = T.dest
// Cells UI binary
os.copy.over(
ui.fastOpt().path,
target / "app" / "cells.js",
createFolders = true
)
os.copy.over(
ui.fastOpt().path / os.up / (ui.fastOpt().path.last+".map"),
target / "app" / (ui.fastOpt().path.last+".map"),
createFolders = true
)
os.write(
target / "app" / "css" / "cells.css",
ui.compiledSass(),
createFolders = true
)
val assets =
ui.html().map { x => (x.path -> os.rel / x.path.last) }++
ui.css().map { x => (x.path -> os.rel / "css" / x.path.last) }++
ui.fonts().map { x => (x.path -> os.rel / "fonts" / x.path.last) }
for((asset, assetTarget) <- assets){
os.copy.over(
asset,
target / "app" / assetTarget,
createFolders = true
)
}
println(s"Generated UI resource dir: $target")
target
}
}