-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCakefile
59 lines (53 loc) · 2.09 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
fs = require 'fs'
{exec} = require 'child_process'
util = require 'util'
appFiles = []
task 'coffeeFiles', 'how much coffee you got?!', ->
traverseFileSystem = (currentPath) ->
files = fs.readdirSync currentPath
for file in files
do (file) ->
currentFile = currentPath + '/' + file
stats = fs.statSync(currentFile)
if stats.isFile() and currentFile.indexOf('.coffee') > 1 and appFiles.join('=').indexOf("#{currentFile}") < 0
util.log currentFile
appFiles.push currentFile
else if stats.isDirectory()
traverseFileSystem currentFile
traverseFileSystem 'src'
util.log "#{appFiles.length} coffee files found."
return appFiles
task 'watch', 'Watch prod source files and build changes', ->
invoke 'build'
util.log "Watching for changes in src"
for file in appFiles then do (file) ->
fs.watchFile file, (curr, prev) ->
if +curr.mtime isnt +prev.mtime
util.log "Saw change in #{file}"
grrrr 'Whoa. Saw a change. Building. Hold plz.'
invoke 'build'
task 'build', 'Build single application file from source files', ->
invoke 'coffeeFiles'
appContents = new Array remaining = appFiles.length
for file, index in appFiles then do (file, index) ->
fs.readFile file, 'utf8', (err, fileContents) ->
throw err if err
appContents[index] = fileContents
process() if --remaining is 0
process = ->
fs.writeFile 'assets/js/app.coffee', appContents.join('\n\n'), 'utf8', (err) ->
throw err if err
exec 'coffee --compile assets/js/app.coffee', (err, stdout, stderr) ->
if err
util.log 'Error compiling coffee file.'
grrrr 'Uh, your coffee is bad.'
else
fs.unlink 'assets/js/app.coffee', (err) ->
if err
util.log 'Couldn\'t delete the app.coffee file/'
util.log 'Done building coffee file.'
grrrr 'Okay, coffee is ready.'
grrrr = (message = '') ->
options =
title: 'CoffeeScript'
util.log " === #{message} ==="