-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCakefile
50 lines (46 loc) · 1.42 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
fs = require 'fs'
{exec} = require 'child_process'
appFiles = [
"shoes"
"dsl"
"app"
"para"
"rect"
"flow"
]
clean = ['lib']
task "build", "Build a single 'shoes-app.js' file", ->
appContents = new Array
remaining = appFiles.length
for file, index in appFiles
do (file, index) ->
fs.readFile "src/#{file}.coffee", 'utf8', (err, fileContents) ->
throw err if err
appContents[index] = fileContents
process(appContents) if --remaining is 0
process = (contents) ->
fs.stat 'lib', (err, stats) ->
throw err if err? and err.code isnt 'ENOENT'
if err?
fs.mkdir 'lib', '0755', (err) ->
throw err if err
console.log 'Created lib directory'
write(contents)
else
write(contents)
write = (contents) ->
# Write concatenated .coffee file temporarily
filename = 'shoes-app'
fs.writeFile "lib/#{filename}.coffee", contents.join('\n\n'), 'utf8', (err) ->
throw err if err
exec "coffee --compile lib/#{filename}.coffee", (err, stdout, stderr) ->
throw err if err
console.log stdout + stderr unless stdout + stderr is ""
# Remove concatenated .coffee file
fs.unlink "lib/#{filename}.coffee", (err) ->
throw err if err
console.log "App compiled to lib/#{filename}.js"
task "clean", "Clean build products", ->
for file in clean
do (file) ->
exec "rm -rf #{file}"