forked from iocrate/netkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.nims
82 lines (79 loc) · 2.54 KB
/
config.nims
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import strutils
import strformat
import os
const ProjectDir = projectDir()
const TestDir = ProjectDir / "tests"
const BuildDir = ProjectDir / "build"
const TestBuildDir = BuildDir / "tests"
const DocBuildEnDir = BuildDir / "doc/en"
const DocBuildZhDir = BuildDir / "doc/zh"
const DocCodeZhDir = ProjectDir / "doc/zh/code"
const DocPolisher = ProjectDir / "tools/docplus/polish.js"
task test, "Run my tests":
# run the following command:
#
# nim test -d:modules=a,b/c,d/e/f
#
# equivalent to:
#
# test tests/a.nim
# test tests/b/c.nim
# test tests/d/e/f.nim
#
const modules {.strdefine.} = ""
let targets = modules.split(",")
for t in targets:
if t.len > 0:
withDir ProjectDir:
var args: seq[string] = @["nim", "c"]
args.add("--run")
args.add("--verbosity:0")
args.add("--hints:off")
args.add(fmt"--out:{TestBuildDir / t}")
args.add(fmt"--path:{ProjectDir}")
args.add(TestDir / t)
rmDir(BuildDir / t.parentDir())
mkDir(TestBuildDir / t.parentDir())
exec(args.join(" "))
task docs, "Gen docs":
# **netkit.nim** is the entry file of this project. This task starts with **netkit.nim** to generate
# the documentation of this project, and the output directory is **${projectDir}/build/doc**.
#
# run the following command:
#
# nim docs [-d:lang=zh|en] [-d:module=netkit/buffer/constants]
#
# Note: nodejs is required, and ``$ npm install`` should be done in **${projectDir}/tools/docplus**.
const lang {.strdefine.} = ""
const module {.strdefine.} = ""
var dirs: seq[tuple[build: string, source: string]] = @[]
case lang
of "":
dirs.add((DocBuildEnDir, ProjectDir))
dirs.add((DocBuildZhDir, DocCodeZhDir))
of "en":
dirs.add((DocBuildEnDir, ProjectDir))
of "zh":
dirs.add((DocBuildZhDir, DocCodeZhDir))
else:
discard
for dir in dirs:
withDir dir.source:
rmDir(dir.build)
mkDir(dir.build)
var args: seq[string] = @["nim", "doc2"]
args.add("--verbosity:0")
args.add("--hints:off")
args.add(fmt"--path:.")
if module.len == 0:
args.add("--project")
args.add("--index:on")
args.add("--git.url:https://github.com/iocrate/netkit")
args.add("--git.commit:master")
args.add(fmt"--out:{dir.build}")
args.add(dir.source / "netkit.nim")
else:
args.add(fmt"--out:{dir.build / module}.html")
args.add(dir.source / module)
exec(args.join(" "))
exec(fmt"DOC_PLUS_ROOT={dir.build} {DocPolisher}")