-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhead.coffee
executable file
·66 lines (49 loc) · 1.33 KB
/
head.coffee
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
#!/usr/bin/env coffee
fs = require('fs')
path = require('path')
CONFIG = require './config'
ROOT = path.resolve __dirname, ".."
lang_order = (lang)->
order = ['en','zh']
pos = order.indexOf(lang)
if pos < 0
pos - order.length
return pos
lang_title = {
zh:"中文说明"
en:"English Readme"
}
README = "readme.md"
make = (dir)->
root = path.join ROOT, dir
dir_doc = path.join(root, "doc")
readme = path.join(dir_doc, "zh",README)
if not fs.existsSync(readme)
return
li = fs.readdirSync(dir_doc)
li.sort (a,b)->
return lang_order(a)-lang_order(b)
txt = [
"# #{CONFIG.PROJECT} "+dir+"\n"
]
for i in li
title = lang_title[i]
txt.push "* [#{title}](##{title.toLowerCase().replace(/\s/,"-")})"
txt.push "\n---\n"
for i in li
title = lang_title[i]
txt.push "## #{title}\n"
readme = fs.readFileSync(path.join(dir_doc, i , README))+""
txt.push readme.trim()
foot = fs.readFileSync(path.join(__dirname, "doc", i , "foot.md"))+""
txt.push "\n"+foot.trim()
txt.push "\n---\n"
txt.push CONFIG.FOOT
fs.writeFileSync path.join(root, README), txt.join("\n")
do =>
fs.readdir(
ROOT
(err, file_li) =>
for i in file_li
make i
)