-
Notifications
You must be signed in to change notification settings - Fork 56
/
Cakefile
76 lines (66 loc) · 2.28 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
chokidar = require('chokidar')
fs = require('fs')
{spawn} = require('child_process')
pug = require('pug')
sass = require('node-sass')
binPath = './node_modules/.bin/'
# Returns a string with the current time to print out.
timeNow = ->
today = new Date()
today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds()
# Spawns an application with `options` and calls `onExit`
# when it finishes.
run = (bin, options, onExit) ->
bin = binPath + bin
console.log timeNow() + ' - running: ' + bin + ' ' + (if options? then options.join(' ') else '')
cmd = spawn bin, options
cmd.stdout.on 'data', (data) -> #console.log data.toString()
cmd.stderr.on 'data', (data) -> console.log data.toString()
cmd.on 'exit', (code) ->
console.log timeNow() + ' - done.'
onExit?(code, options)
compileView = (done) ->
options = ['--pretty', 'src/views/api_mate.pug', '--out', 'lib', '--obj', 'src/pug_options.json']
run 'pug', options, ->
options = ['--pretty', 'src/views/redis_events.pug', '--out', 'lib', '--obj', 'src/pug_options.json']
run 'pug', options, ->
done?()
compileCss = (done) ->
options = ['src/css/api_mate.scss', 'lib/api_mate.css']
run 'node-sass', options, ->
options = ['src/css/redis_events.scss', 'lib/redis_events.css']
run 'node-sass', options, ->
done?()
compileJs = (done) ->
options = [
'-o', 'lib',
'--join', 'api_mate.js',
'--compile', 'src/js/application.coffee', 'src/js/templates.coffee', 'src/js/api_mate.coffee'
]
run 'coffee', options, ->
options = [
'-o', 'lib',
'--join', 'redis_events.js',
'--compile', 'src/js/application.coffee', 'src/js/redis_events.coffee'
]
run 'coffee', options, ->
done?()
build = (done) ->
compileView (err) ->
compileCss (err) ->
compileJs (err) ->
done?()
watch = () ->
watcher = chokidar.watch('src', { ignored: /[\/\\]\./, persistent: true })
watcher.on 'all', (event, path) ->
console.log timeNow() + ' = detected', event, 'on', path
if path.match(/\.coffee$/)
compileJs()
else if path.match(/\.scss/)
compileCss()
else if path.match(/\.pug/)
compileView()
task 'build', 'Build everything from src/ into lib/', ->
build()
task 'watch', 'Watch for changes to compile the sources', ->
watch()