From 29a606951d70a8417a70c456a1cc87d73909ce00 Mon Sep 17 00:00:00 2001 From: Alex Archambault Date: Mon, 17 Feb 2025 14:59:47 +0100 Subject: [PATCH] Tweak doc watch mode handling --- build.sc | 20 ++++++++++++++++++-- docs/pages/develop.md | 9 ++------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/build.sc b/build.sc index 36a9aa78..326b7806 100644 --- a/build.sc +++ b/build.sc @@ -511,9 +511,25 @@ object docs extends ScalaModule { } def mkdocsServe() = T.command[Unit] { mdoc()() - os.proc("mkdocs", "serve", mkdocsConfigArgs()) - .call(cwd = millModuleBasePath.value, stdin = os.Inherit, stdout = os.Inherit) + val docsDir = T.workspace / "docs" + val serveProc = os.proc("mkdocs", "serve", mkdocsConfigArgs()) + .spawn(cwd = docsDir, stdin = os.Inherit, stdout = os.Inherit) + val mdocProc = os.proc( + "java", + "-cp", + compileClasspath().map(_.path).mkString(File.pathSeparator), + mainClass().getOrElse(???), + mdocWatchArgs().value + ) + .spawn(cwd = docsDir, stdin = os.Inherit, stdout = os.Inherit) + + while (serveProc.isAlive && mdocProc.isAlive) + Thread.sleep(1000L) + val serveRetCode = serveProc.waitFor() + val mdocRetCode = mdocProc.waitFor() + if (serveRetCode != 0 || mdocRetCode != 0) + sys.error(s"Got exit code $serveRetCode for mkdocs serve and $mdocRetCode for mdoc") () } def mkdocsBuild() = T.command[Unit] { diff --git a/docs/pages/develop.md b/docs/pages/develop.md index d0089781..074ae997 100644 --- a/docs/pages/develop.md +++ b/docs/pages/develop.md @@ -4,14 +4,9 @@ ### Watch mode -In a first terminal, run +Run ```text -$ ./mill -i -w docs.mdocWatch -``` - -Leave it running, and run in a second terminal -```text -$ ./mill -i -w docs.mkdocsServe +$ ./mill -i docs.mkdocsServe ``` Then open the URL printed in the console in your browser (it should be