forked from mconf/api-mate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cakefile
75 lines (65 loc) · 2.07 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
chokidar = require('chokidar')
fs = require('fs')
{print} = require('sys')
{spawn} = require('child_process')
jade = require('jade')
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) -> #print data.toString()
cmd.stderr.on 'data', (data) -> print data.toString()
cmd.on 'exit', (code) ->
console.log timeNow() + ' - done.'
onExit?(code, options)
compileView = (done) ->
options = ['--pretty', 'src/views/api_mate.jade', '--out', 'lib']
run 'jade', options, ->
done?()
compileCss = (done) ->
options = ['src/css/api_mate.scss', 'lib/api_mate.css']
run 'node-sass', options, ->
options = ['src/css/application.scss', 'lib/application.css']
run 'node-sass', options, ->
done?()
compileJs = (done) ->
options = [
'-o', 'lib',
'--join', 'api_mate.js',
'--compile', 'src/js/templates.coffee', 'src/js/api_mate.coffee'
]
run 'coffee', options, ->
options = [
'-o', 'lib',
'--join', 'application.js',
'--compile', 'src/js/application.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(/\.jade/)
compileView()
task 'build', 'Build everything from src/ into lib/', ->
build()
task 'watch', 'Watch for changes to compile the sources', ->
watch()