forked from jackiealex/nobone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCakefile
167 lines (141 loc) · 4.01 KB
/
Cakefile
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
process.env.NODE_ENV = 'development'
kit = require './lib/kit'
{ Promise, _ } = kit
option '-d', '--debug', 'Node debug mode'
option '-p', '--port [port]', 'Node debug mode'
task 'dev', 'Dev Server', (opts) ->
app_path = 'test/lab.coffee'
if opts.debug
port = opts.port or 8283
args = ['--nodejs', '--debug-brk=' + port, app_path]
else
args = [app_path]
kit.monitor_app {
bin: 'coffee'
args
watch_list: ['test/lab.coffee', 'lib/**/*.coffee']
}
task 'test', 'Basic test', (options) ->
build().then ->
[
# 'test/single.coffee'
'test/basic.coffee'
].forEach (file) ->
kit.spawn('mocha', [
'-t', 30 * 1000
'-r', 'coffee-script/register'
'-R', 'spec'
file
]).process.on 'exit', (code) ->
if code != 0
process.exit code
.done()
task 'build', 'Compile coffee and Docs', build = ->
kit.log "Compile coffee..."
kit.spawn 'coffee', [
'-o', 'dist'
'-cb', 'lib'
]
# Build readme
kit.log 'Make readme...'
Promise.all([
kit.readFile 'doc/faq.md', 'utf8'
kit.readFile 'doc/readme.ejs.md', 'utf8'
kit.readFile 'examples/basic.coffee', 'utf8'
kit.readFile 'benchmark/mem_vs_stream.coffee', 'utf8'
kit.readFile 'benchmark/crc_vs_jhash.coffee', 'utf8'
]).then (rets) ->
faq = rets[0]
basic = rets[2]
{
tpl: rets[1]
basic
faq
mods: [
'lib/nobone.coffee'
'lib/modules/service.coffee'
'lib/modules/renderer.coffee'
'lib/modules/db.coffee'
'lib/modules/proxy.coffee'
'lib/kit.coffee'
]
benchmark: kit.parse_comment 'benchmark', rets[3] + rets[4]
}
.then (data) ->
Promise.all data.mods.map (path) ->
name = kit.path.basename path, '.coffee'
kit.readFile path, 'utf8'
.then (code) ->
kit.parse_comment name, code, path
.then (rets) ->
data.mods = _.groupBy _.flatten(rets, true), (el) -> el.module
data
.then (data) ->
ejs = require 'ejs'
data._ = _
indent = (str, num = 0) ->
s = _.range(num).reduce ((s) -> s + ' '), ''
s + str.trim().replace(/\n/g, '\n' + s)
data.mods_api = ''
for mod_name, mod of data.mods
data.mods_api += """### #{mod_name}\n\n"""
for method in mod
method.name = method.name.replace 'self.', ''
method_str = indent """
- #### <a href="#{method.path}#L#{method.line}" target="_blank"><b>#{method.name}</b></a>
"""
method_str += '\n\n'
if method.description
method_str += indent method.description, 1
method_str += '\n\n'
if _.any(method.tags, { tag_name: 'private' })
continue
for tag in method.tags
tname = if tag.name then "`#{tag.name}`" else ''
ttype = if tag.type then "{ _#{tag.type}_ }" else ''
method_str += indent """
- **<u>#{tag.tag_name}</u>**: #{tname} #{ttype}
""", 1
method_str += '\n\n'
if tag.description
method_str += indent tag.description, 4
method_str += '\n\n'
data.mods_api += method_str
out = ejs.render data.tpl, data
kit.outputFile 'readme.md', out
.then()
task 'clean', 'Clean js', ->
kit.log ">> Clean js..."
kit.remove('dist').done()
# Just for fun.
task 'code', 'Code Statistics of this project', ->
line_count = 0
size_count = 0
kit.glob [
'assets', 'benchmark', 'bin', 'bone', 'doc', 'examples', 'lib', 'test'
].map (el) -> el + '/**/*.+(js|coffee|styl|css|md|ejs|html)'
.then (paths) ->
paths.push 'Cakefile'
kit.log ' File Count: '.cyan + paths.length
kit.async 20, (i) ->
if i >= paths.length
return
Promise.all [
kit.readFile paths[i], 'utf8'
kit.stat paths[i]
]
, false, ([str, stats]) ->
line_count += str.split('\n').length
size_count += stats.size
.done ->
kit.log 'Total Lines: '.cyan + line_count
kit.log ' Total Size: '.cyan + (size_count / 1024).toFixed(2) + ' kb'
task 'hotfix', 'Hotfix third dependencies\' bugs', ->
# ys: Node break again and again.
task 'benchmark', 'Some basic benchmarks', ->
server = kit.spawn('coffee', ['benchmark/load_test_server.coffee'])
setTimeout ->
tester = kit.spawn('coffee', ['benchmark/mem_vs_stream.coffee'])
tester.done ->
server.process.kill "SIGINT"
, 500