mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-21 09:58:26 +00:00
Update build for new website
This commit is contained in:
113
project/ZolaPlugin.scala
Normal file
113
project/ZolaPlugin.scala
Normal file
@ -0,0 +1,113 @@
|
||||
package docspell.build
|
||||
|
||||
import sbt._
|
||||
import sbt.Keys._
|
||||
import scala.sys.process._
|
||||
|
||||
object ZolaPlugin extends AutoPlugin {
|
||||
|
||||
object autoImport {
|
||||
val zolaRootDir = settingKey[File]("The root directory of zola")
|
||||
val zolaOutputDir = settingKey[File]("The directory to put the final site")
|
||||
val zolaCommand = settingKey[String]("The zola executable")
|
||||
val zolaTestBaseUrl =
|
||||
settingKey[String]("The base-url to use when building the test site.")
|
||||
|
||||
val zolaBuild = taskKey[Unit](
|
||||
"Build the site using zola, which is then available in 'zolaOutputDir'."
|
||||
)
|
||||
val zolaBuildTest = taskKey[Unit](
|
||||
"Build the site using zola, which is then available in 'zolaOutputDir'. " +
|
||||
"It uses a different base-url. So the final site can be tested using " +
|
||||
"'python -m SimpleHTTPServer 1234' for example."
|
||||
)
|
||||
val zolaCheck = taskKey[Unit]("Runs zola check to check links")
|
||||
}
|
||||
|
||||
import autoImport._
|
||||
|
||||
def zolaSettings: Seq[Setting[_]] =
|
||||
Seq(
|
||||
zolaRootDir := baseDirectory.value / "site",
|
||||
zolaOutputDir := target.value / "zola-site",
|
||||
zolaCommand := "zola",
|
||||
zolaTestBaseUrl := "http://localhost:1234",
|
||||
zolaBuild := {
|
||||
val logger = streams.value.log
|
||||
logger.info("Building web site using zola ...")
|
||||
buildSite(zolaCommand.value, zolaRootDir.value, zolaOutputDir.value, None, logger)
|
||||
logger.info("Website built")
|
||||
},
|
||||
zolaBuildTest := {
|
||||
val logger = streams.value.log
|
||||
val baseurl = zolaTestBaseUrl.value
|
||||
logger.info("Building web site (test) using zola ...")
|
||||
buildSite(
|
||||
zolaCommand.value,
|
||||
zolaRootDir.value,
|
||||
zolaOutputDir.value,
|
||||
Some(baseurl),
|
||||
logger
|
||||
)
|
||||
logger.info(s"Website built. Check it with base-url $baseurl")
|
||||
},
|
||||
zolaCheck := {
|
||||
val logger = streams.value.log
|
||||
logger.info("Checking web site using zola ...")
|
||||
checkSite(zolaCommand.value, zolaRootDir.value, logger)
|
||||
}
|
||||
)
|
||||
|
||||
override def projectSettings: Seq[Setting[_]] =
|
||||
zolaSettings
|
||||
|
||||
def buildSite(
|
||||
zolaCmd: String,
|
||||
inDir: File,
|
||||
outDir: File,
|
||||
base: Option[String],
|
||||
logger: Logger
|
||||
): Unit = {
|
||||
val baseUrl = base match {
|
||||
case Some(url) =>
|
||||
Seq("--base-url", url)
|
||||
case None =>
|
||||
runYarnInstall("yarn", inDir.getParentFile, logger)
|
||||
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
|
||||
)
|
||||
val proc = Process(cmd, Some(inDir))
|
||||
val out = proc.!!
|
||||
logger.info(out)
|
||||
}
|
||||
|
||||
}
|
@ -1,14 +1,18 @@
|
||||
with import <nixpkgs> { };
|
||||
let
|
||||
initScript = writeScript "docspell-build-init" ''
|
||||
nixpkgsUnstable = builtins.fetchTarball {
|
||||
url = "https://github.com/NixOS/nixpkgs-channels/archive/nixos-unstable.tar.gz";
|
||||
};
|
||||
pkgsUnstable = import nixpkgsUnstable { };
|
||||
initScript = pkgsUnstable.writeScript "docspell-build-init" ''
|
||||
export LD_LIBRARY_PATH=
|
||||
${bash}/bin/bash -c sbt
|
||||
${pkgsUnstable.bash}/bin/bash -c sbt
|
||||
'';
|
||||
in
|
||||
in with pkgsUnstable;
|
||||
|
||||
buildFHSUserEnv {
|
||||
name = "docspell-sbt";
|
||||
targetPkgs = pkgs: with pkgs; [
|
||||
netcat jdk8 wget which zsh dpkg sbt git elmPackages.elm ncurses fakeroot mc jekyll
|
||||
netcat jdk8 wget which zsh dpkg sbt git elmPackages.elm ncurses fakeroot mc
|
||||
zola yarn
|
||||
|
||||
# haskells http client needs this (to download elm packages)
|
||||
|
@ -1,9 +1,9 @@
|
||||
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.9.19")
|
||||
addSbtPlugin("com.47deg" % "sbt-microsites" % "1.2.1")
|
||||
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.9.0")
|
||||
addSbtPlugin("com.github.eikek" % "sbt-openapi-schema" % "0.6.1")
|
||||
addSbtPlugin("com.github.gseitz" % "sbt-release" % "1.0.13")
|
||||
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "2.0.1")
|
||||
addSbtPlugin("com.typesafe.sbt" % "sbt-ghpages" % "0.6.3")
|
||||
addSbtPlugin("com.typesafe.sbt" % "sbt-git" % "1.0.0")
|
||||
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.7.4")
|
||||
addSbtPlugin("io.spray" % "sbt-revolver" % "0.9.1")
|
||||
|
Reference in New Issue
Block a user