-
Notifications
You must be signed in to change notification settings - Fork 158
/
Cakefile
93 lines (72 loc) · 2.68 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
fs = require 'fs'
{exec} = require 'child_process'
util = require 'util'
{jsmin} = require 'jsmin'
targetName = "ajax-chosen"
###
CoffeeScript Options
###
csSrcDir = "src"
csTargetDir = "lib"
targetCoffee = "#{csSrcDir}/build.coffee"
targetJS = "#{csTargetDir}/#{targetName}.js"
targetMinJS = "#{csTargetDir}/#{targetName}.min.js"
coffeeOpts = "-b -j #{targetName}.js -o #{csTargetDir} -c #{targetCoffee}"
coffeeFiles = [
"ajax-chosen"
]
###
Event System
###
finishedCallback = {}
finished = (type) ->
finishedCallback[type]() if finishedCallback[type]?
finishListener = (type, cb) ->
finishedCallback[type] = cb
notify = (msg) ->
return if not growl?
growl.notify msg, {title: "Heello Development", image: "Terminal"}
###
Tasks
###
task 'docs', 'Generates documentation for the coffee files', ->
util.log 'Invoking docco on the CoffeeScript source files'
files = coffeeFiles
files[i] = "#{csSrcDir}/#{files[i]}.coffee" for i in [0...files.length]
exec "docco #{files.join(' ')}", (err, stdout, stderr) ->
util.log err if err
util.log "Documentation built into docs/ folder."
task 'watch', 'Automatically recompile the CoffeeScript files when updated', ->
util.log "Watching for changes in #{csSrcDir}"
for jsFile in coffeeFiles then do (jsFile) ->
fs.watchFile "#{csSrcDir}/#{jsFile}.coffee", (curr, prev) ->
if +curr.mtime isnt +prev.mtime
util.log "#{csSrcDir}/#{jsFile}.coffee updated"
invoke 'build'
task 'build', 'Compile and minify all CoffeeScript source files', ->
finishListener 'js', -> invoke 'minify'
invoke 'compile'
task 'compile', 'Compile all CoffeeScript source files', ->
util.log "Building #{targetJS}"
contents = []
remaining = coffeeFiles.length
util.log "Appending #{coffeeFiles.length} files to #{targetCoffee}"
for file, index in coffeeFiles then do (file, index) ->
fs.readFile "#{csSrcDir}/#{file}.coffee", "utf8", (err, fileContents) ->
util.log err if err
contents[index] = fileContents
util.log "[#{index + 1}] #{file}.coffee"
process() if --remaining is 0
process = ->
fs.writeFile targetCoffee, contents.join("\n\n"), "utf8", (err) ->
util.log err if err
exec "coffee #{coffeeOpts}", (err, stdout, stderr) ->
util.log err if err
util.log "Compiled #{targetJS}"
fs.unlink targetCoffee, (err) -> util.log err if err
finished('js')
task 'minify', 'Minify the CoffeeScript files', ->
util.log "Minifying #{targetJS}"
fs.readFile targetJS, "utf8", (err, contents) ->
fs.writeFile targetMinJS, jsmin(contents), "utf8", (err) ->
util.log err if err