-
Notifications
You must be signed in to change notification settings - Fork 1
/
docs.vsh
48 lines (43 loc) · 1.26 KB
/
docs.vsh
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
/**
* All credit for this script goes to Turiiya (AKA ttytm) as its part of his build script, it was taken from his Webview project and slightly modified.
* https://github.com/ttytm/webview
**/
import cli
import os
import regex
// Remove redundant readme section from module page.
fn rm_readme_section(html string) string {
mut r := regex.regex_opt(r'<section id="readme_vtray".*</section>') or { panic(err) }
sec_start, sec_end := r.find(html)
return '${html[..sec_start]}</section>${html[sec_end..]}'
.replace('<li class="open"><a href="#readme_vtray">README</a></li>', '')
}
fn build_docs() ! {
// Cleanup old docs.
rmdir_all('_docs') or {}
// Build docs.
mut p := new_process(@VEXE)
p.set_args(['doc', '-readme', '-m', '-f', 'html', '.'])
p.wait()
// Prepare html.
mut vtray_html := read_file('_docs/vtray.html')!
vtray_html = rm_readme_section(vtray_html)
write_file('_docs/vtray.html', vtray_html)!
os.cp_all('assets', '_docs/assets', true)!
}
mut cmd := cli.Command{
name: 'build.vsh'
posix_mode: true
required_args: 0
pre_execute: fn (cmd cli.Command) ! {
if cmd.args.len > cmd.required_args {
eprintln('Unknown commands ${cmd.args}.\n')
cmd.execute_help()
exit(0)
}
}
execute: fn (_cmd cli.Command) ! {
build_docs()!
}
}
cmd.parse(os.args)