Website tweaks

This commit is contained in:
Eike Kettner
2020-07-31 15:13:07 +02:00
parent 808a5a3c94
commit 4f6597f358
13 changed files with 151 additions and 103 deletions

40
project/Cmd.scala Normal file
View File

@ -0,0 +1,40 @@
package docspell.build
import sbt._
import scala.sys.process._
import java.util.concurrent.atomic.AtomicReference
/** Helper for running external commands. */
object Cmd {
case class Result(rc: Int, out: String, err: String) {
def throwIfNot(success: Int): Result =
if (rc != success) sys.error(s"Unsuccessful return: $rc")
else this
}
def run(cmd: Seq[String], wd: File, logger: Logger): Unit = {
val res = Cmd.exec(cmd, Some(wd))
logger.info(res.out)
logger.error(res.err)
res.throwIfNot(0)
}
def exec(cmd: Seq[String], wd: Option[File]): Result = {
val capt = new Capture
val rc = Process(cmd, wd).!(capt.logger)
Result(rc, capt.out.get.mkString("\n"), capt.err.get.mkString("\n"))
}
final private class Capture {
val err = new AtomicReference[List[String]](Nil)
val out = new AtomicReference[List[String]](Nil)
val logger = ProcessLogger(
line => out.getAndAccumulate(List(line), _ ++ _),
line => err.getAndAccumulate(List(line), _ ++ _)
)
}
}

View File

@ -76,38 +76,31 @@ object ZolaPlugin extends AutoPlugin {
runElmCompile("elm", inDir.getParentFile, outDir, logger)
Seq.empty
}
val cmd = Seq(zolaCmd, "build", "-o", outDir.absolutePath.toString) ++ baseUrl
val proc = Process(cmd, Some(inDir))
val out = proc.!!
logger.info(out)
}
def checkSite(zolaCmd: String, inDir: File, logger: Logger): Unit = {
val cmd = Seq(zolaCmd, "check")
val proc = Process(cmd, Some(inDir))
val out = proc.!!
logger.info(out)
}
def runYarnInstall(yarnCmd: String, inDir: File, logger: Logger): Unit = {
val cmd = Seq(yarnCmd, "install")
val proc = Process(cmd, Some(inDir))
val out = proc.!!
logger.info(out)
}
def runElmCompile(elmCmd: String, inDir: File, zolaOut: File, logger: Logger): Unit = {
val cmd = Seq(
elmCmd,
"make",
"--output",
(zolaOut / "static" / "js" / "bundle.js").absolutePath.toString,
"--optimize",
(inDir/"elm"/"Main.elm").toString
Cmd.run(
Seq(zolaCmd, "build", "-o", outDir.absolutePath.toString) ++ baseUrl,
inDir,
logger
)
val proc = Process(cmd, Some(inDir))
val out = proc.!!
logger.info(out)
}
def checkSite(zolaCmd: String, inDir: File, logger: Logger): Unit =
Cmd.run(Seq(zolaCmd, "check"), inDir, logger)
def runYarnInstall(yarnCmd: String, inDir: File, logger: Logger): Unit =
Cmd.run(Seq(yarnCmd, "install"), inDir, logger)
def runElmCompile(elmCmd: String, inDir: File, zolaOut: File, logger: Logger): Unit =
Cmd.run(
Seq(
elmCmd,
"make",
"--output",
(zolaOut / "static" / "js" / "bundle.js").absolutePath.toString,
"--optimize",
(inDir / "elm" / "Main.elm").toString
),
inDir,
logger
)
}