From acc7f6cef0e9bc5b6debb52c88616aaba9dbce80 Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Fri, 9 Oct 2020 10:13:10 -0700 Subject: [PATCH] add docs; add fusion/docutils --- fusion.nimble | 6 +++++- src/fusion/docutils.nim | 29 +++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 src/fusion/docutils.nim diff --git a/fusion.nimble b/fusion.nimble index 835f0aec..877a33f2 100644 --- a/fusion.nimble +++ b/fusion.nimble @@ -8,5 +8,9 @@ srcDir = "src" # Dependencies - requires "nim >= 1.0.0" + +task docs, "": + # can customize, eg: + # exec "nim r src/fusion/docutils " & srcDir & " --outdir:htmldocs2 -d:foo" + exec "nim r src/fusion/docutils " & srcDir diff --git a/src/fusion/docutils.nim b/src/fusion/docutils.nim new file mode 100644 index 00000000..78bd1025 --- /dev/null +++ b/src/fusion/docutils.nim @@ -0,0 +1,29 @@ +import std/[os,strformat,sugar,osproc] +import std/private/globs + +iterator findNimSrcFiles*(dir: string): string = + proc follow(a: PathEntry): bool = + a.path.lastPathPart notin ["nimcache", "htmldocs"] + for entry in walkDirRecFilter(dir, follow = follow): + if entry.path.splitFile.ext == ".nim" and entry.kind == pcFile: + yield entry.path + +proc genCodeImportAll*(dir: string): string = + result = "{.warning[UnusedImport]: off.}\n" + for a in findNimSrcFiles(dir): + let s = "".dup(addQuoted(a)) + result.add &"import {s}\n" + +proc genDocs(dir: string, nim = "", args: seq[string]) = + let code = genCodeImportAll(dir) + let extra = quoteShellCommand(args) + let nim = if nim.len == 0: getCurrentCompilerExe() else: nim + let ret = execCmdEx(fmt"{nim} doc -r --project --docroot --outdir:htmldocs {extra} -", input = code) + if ret.exitCode != 0: + doAssert false, ret.output & "\n" & code + +when isMainModule: + let args = commandLineParams() + doAssert args.len >= 1 + let dir = args[0] + genDocs(dir, nim="", args[1..^1])