-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cakefile
122 lines (87 loc) · 2.75 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
require.main.paths.push './server/submodules'
fs = require 'fs'
{exec} = require 'child_process'
colors = require 'colors'
watch = require 'watch'
cs = require 'coffee-script'
colors.setTheme
'positive' : 'green'
'ordinary' : 'yellow'
'critical' : 'red'
Array::last = ->
return @[@length-1]
log = (message, code, error) ->
f = (value) ->
return value < 10 and "0#{value}" or "#{value}"
actualTime = (d = new Date) ->
date = "#{f(d.getMonth()+1)}/#{f(d.getDate())}/#{d.getFullYear()}"
time = "#{f(d.getHours())}:#{f(d.getMinutes())}:#{f(d.getSeconds())}"
return "#{date} #{time}"
space = ->
return [1..19].map(->' ').join ''
if typeof code isnt 'undefined'
console.log "|#{actualTime()[code]}| #{message[code]}"
console.log "|#{space()}| #{error.toString()[code]}" if error
else
console.log "|#{actualTime()}| #{message}"
sources = [
'client/modules',
'server/modules',
'loader'
]
cleanJavascript = (ondone) ->
log 'Cleaning javascript'
exec "rm -r $(find -name 'js')", ->
do ondone
cleanDocumentation = (ondone) ->
log 'Cleaning documentation'
exec "rm -r documentation/client documentation/server documentation/loader", ->
do ondone
task 'document', 'document sources', ->
log 'Generating documentation'
cleanDocumentation ->
exec 'mkdir documentation'
sources.forEach (path) ->
exec "mkdir documentation/#{path}"
exec "docco #{path}/coffee/* -o documentation/#{path} -c documentation/docco.css"
task 'watch', 'watch coffee files', ->
log 'Watching: coffee files', 'positive'
log 'Compiling javascript'
errors = {}
compile = (path, output) ->
fs.readFile path, 'utf8', (error, code) ->
if error
log 'Error reading file', 'critical', error
return
index = null
parts = path.split '/'
parts.some (p, i) ->
if p is 'coffee'
return index = i+1
name = parts[index...].join('_')
name = name.replace '.coffee', '.js'
try
compiled = cs.compile code
catch error
errors[path] = true
log "Error compiling: #{path}", 'ordinary', error
return
filename = path.split(/\//g).last().replace('.coffee', '.js')
fs.writeFile "#{output}/#{name}", compiled, (error) ->
if error
log 'Error writing file', 'critical', error
else if errors[path] and delete errors[path]
log "Compiled: \"#{path}\"", 'positive'
else
log "Compiled: \"#{path}\""
monitor = (path, output) ->
watch.createMonitor path, (monitor) ->
monitor.on 'changed', (path, current, previous) ->
compile path, output
for path of monitor.files
compile path, output if /\.coffee/.test path
cleanJavascript ->
sources.forEach (directory) ->
[path, output] = ("#{directory}/#{language}" for language in ['coffee', 'js'])
exec "mkdir #{output}"
monitor path, output