forked from revskill/CoreJS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cakefile
64 lines (48 loc) · 2.11 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
# CoreJS Cakefile
# ======================
watchFiles = ['master.coffee', 'staging', 'production.coffee', 'framework', 'app']
fs = require 'fs'
{spawn, exec} = require 'child_process'
logCallback = (data) -> if data? then console.log data.toString().trim()
getFiles = (callback) ->
find = exec 'find . | grep "\\.coffee$"', (error, stdout, stderr) ->
unless error then callback.call this, stdout.split('\n')
else throw error
task 'build', 'Build project', ->
coffee = spawn 'coffee', [ '-b', '-c', watchFiles...]
coffee.stdout.on 'data', logCallback
task 'watch', 'Watch Project', ->
coffee = spawn 'coffee', [ '-b', '-c', '-w', watchFiles...]
coffee.stdout.on 'data', logCallback
task 'clean', 'Clean Project', ->
getFiles (data) ->
command = ['rm -vf']
nodeModules = /\/node_modules\//
hidden = /^\.\/\./
coffeeFile = /\.coffee$/
command.push item.replace(coffeeFile, '.js') for item in data when not nodeModules.test(item) and not hidden.test(item)
exec command.join(' '), (err, stdout, stderr) -> if err then throw err else console.log stdout
task 'doc', 'Build Docs', ->
extraCSS = '''
/* CSS Overrides */
td.docs, th.docs { overflow: auto !important; }
'''
command = "
rm -Rf docs;
docco framework/*.coffee framework/classes/*.coffee;
"
exec command, ->
# Patch index.html
indexBuf = fs.readFileSync 'docs/index.html', 'utf-8'
fs.writeFileSync 'docs/index.html', indexBuf.replace(/index\.coffee/g, 'CoreJS Documentation'), 'utf-8'
# Patch doc files
files = fs.readdirSync 'docs'
htmlFile = /\.html$/
title = /<h1>(\s+)(.*?)(\s+)<\/h1>/
for file in files
if file is 'index.html' or not htmlFile.test(file) then continue
buf = fs.readFileSync "docs/#{file}", 'utf-8'
fs.writeFileSync "docs/#{file}", buf.replace(title, '<br/><p><a style="text-decoration: none; font-size: 14px; font-weight: normal; background: #f5f5ff; padding: 3px 5px; border-radius: 5px; border: solid 1px #d3d3dc;" href="index.html">← Back to index</a></p>'), 'utf-8'
# Patch css
doccoCSS = fs.readFileSync "docs/docco.css", 'utf-8'
fs.writeFileSync "docs/docco.css", (doccoCSS + extraCSS), 'utf-8'