2023-04-22 20:20:37 +00:00
|
|
|
import Lake
|
2023-05-03 21:31:33 +00:00
|
|
|
|
2023-04-22 20:20:37 +00:00
|
|
|
open Lake DSL
|
|
|
|
|
|
|
|
package «bookshelf»
|
|
|
|
|
|
|
|
require mathlib from git
|
|
|
|
"https://github.com/leanprover-community/mathlib4.git" @
|
2023-05-03 21:31:33 +00:00
|
|
|
"d65ed3b2920dbfb0b2bf1aca2189ec177eb68980"
|
2023-05-02 15:14:50 +00:00
|
|
|
require std4 from git
|
|
|
|
"https://github.com/leanprover/std4.git" @
|
|
|
|
"6006307d2ceb8743fea7e00ba0036af8654d0347"
|
2023-05-03 21:31:33 +00:00
|
|
|
require «doc-gen4» from git
|
2023-05-04 17:50:19 +00:00
|
|
|
"https://github.com/jrpotter/bookshelf-docgen.git" @
|
2023-05-11 01:09:41 +00:00
|
|
|
"87ecc512444afd073a2b201ef25caf3ef5fc74b1"
|
2023-04-22 20:20:37 +00:00
|
|
|
|
|
|
|
@[default_target]
|
|
|
|
lean_lib «Bookshelf» {
|
2023-05-08 19:43:54 +00:00
|
|
|
roots := #[`Bookshelf, `Common]
|
2023-04-22 20:20:37 +00:00
|
|
|
}
|
2023-05-03 21:31:33 +00:00
|
|
|
|
|
|
|
/--
|
|
|
|
The contents of our `.env` file.
|
|
|
|
-/
|
|
|
|
structure Config where
|
|
|
|
port : Nat := 5555
|
|
|
|
|
|
|
|
/--
|
|
|
|
Read in the `.env` file into an in-memory structure.
|
|
|
|
-/
|
|
|
|
private def readConfig : StateT Config ScriptM Unit := do
|
|
|
|
let env <- IO.FS.readFile ".env"
|
|
|
|
for line in env.trim.split (fun c => c == '\n') do
|
|
|
|
match line.split (fun c => c == '=') with
|
|
|
|
| ["PORT", port] => modify (fun c => { c with port := String.toNat! port })
|
|
|
|
| _ => error "Malformed `.env` file."
|
|
|
|
return ()
|
|
|
|
|
|
|
|
/--
|
|
|
|
Start an HTTP server for locally serving documentation. It is expected the
|
|
|
|
documentation has already been generated prior via
|
|
|
|
|
|
|
|
```bash
|
|
|
|
> lake build Bookshelf:docs
|
|
|
|
```
|
|
|
|
|
|
|
|
USAGE:
|
2023-05-04 17:50:19 +00:00
|
|
|
lake run server
|
2023-05-03 21:31:33 +00:00
|
|
|
-/
|
2023-05-04 17:50:19 +00:00
|
|
|
script server (_args) do
|
2023-05-03 21:31:33 +00:00
|
|
|
let ((), config) <- StateT.run readConfig {}
|
2023-05-04 17:50:19 +00:00
|
|
|
IO.println s!"Running Lean on `http://localhost:{config.port}`"
|
2023-05-03 21:31:33 +00:00
|
|
|
_ <- IO.Process.run {
|
|
|
|
cmd := "python3",
|
2023-05-04 17:50:19 +00:00
|
|
|
args := #["-m", "http.server", toString config.port, "-d", "build/doc"],
|
2023-05-03 21:31:33 +00:00
|
|
|
}
|
|
|
|
return 0
|