1- import std/ [os, strformat, sugar , osproc]
1+ import std/ [os, sugar, strutils , osproc]
22import std/ private/ globs
33
44
5- const blockList =
6- when not defined (js): [" nimcache" , " htmldocs" , " js" ]
7- else : [" nimcache" , " htmldocs" ]
5+ const
6+ blockList = [" nimcache" , " htmldocs" ] # Folders to explicitly ignore.
7+ baseCmd = " doc --project --docroot --outdir:htmldocs --styleCheck:hint " # nim doc command part that never changes
8+ jsDocOpts = # nim doc command part that changes for JS compat.
9+ when defined (fusionDocJs): " -b:js "
10+ else : " "
11+ docComand = baseCmd & jsDocOpts
12+
813
914iterator findNimSrcFiles * (dir: string ): string =
10- proc follow (a: PathEntry ): bool =
15+ func follow (a: PathEntry ): bool =
1116 a.path.lastPathPart notin blockList
1217
1318 for entry in walkDirRecFilter (dir, follow = follow):
@@ -17,18 +22,24 @@ iterator findNimSrcFiles*(dir: string): string =
1722
1823proc genCodeImportAll * (dir: string ): string =
1924 result = " {.warning[UnusedImport]: off.}\n "
20- for a in findNimSrcFiles (dir):
21- let s = " " .dup (addQuoted (a))
22- result .add & " import { s} \n "
25+ var name, prefix: string
26+ for nimfile in findNimSrcFiles (dir):
27+ name = nimfile.extractFilename
28+ prefix =
29+ if name.startsWith " js" :
30+ " when defined(js): import "
31+ else :
32+ " when not defined(js): import "
33+ result .add prefix & " " .dup (addQuoted (nimfile)) & " \n "
2334
2435
2536proc genDocs (dir: string , nim = " " , args: seq [string ]) =
2637 let code = genCodeImportAll (dir)
2738 let extra = quoteShellCommand (args)
2839 let nim = if nim.len == 0 : getCurrentCompilerExe () else : nim
29- let ret = execCmdEx (fmt " { nim} doc -r --project --docroot --outdir:htmldocs { extra } - " , input = code)
40+ let ret = execCmdEx (nim & docComand & extra & " - " , input = code)
3041 if ret.exitCode != 0 :
31- doAssert false , ret.output & " \n " & code
42+ doAssert false , ret.output & ' \n ' & code
3243
3344
3445when isMainModule :
0 commit comments