-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cakefile
105 lines (84 loc) · 3.3 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
94
95
96
97
98
99
100
101
102
103
104
105
# Hello developer!
# This is a cakefile for Flow project
# Copyright 2012 by Bartek Kubiak
{spawn} = require 'child_process'
CoffeeScript = require 'coffee-script'
fs = require 'fs'
watch = require 'watch'
Snockets = require 'snockets'
snockets = new Snockets
async: false
libraries = [
'jquery-1.9.1'
'underscore-1.4.3'
'backbone-0.9.9'
'backbone-ext'
'jquery-ui-core-1.10.1'
'jquery-ui-widget-1.10.1'
'jquery-ui-mouse-1.10.1'
'jquery-ui-slider-1.10.1'
'd3-3.0.8'
'd3-tooltip-1.0.0'
]
lastBuildAppTime = 0
helpers =
addLeadingZero: (x) ->
x = parseInt(x, 10)
if 0 <= x < 10
return '0'+x
return x
formatTime: (date) ->
time = @addLeadingZero date.getHours()
time += ':' + @addLeadingZero date.getMinutes()
time += ':' + @addLeadingZero date.getSeconds()
task 'run', 'Run the server and watch for changes to rebuild the app', ->
invoke 'watch-src'
invoke 'run-server'
task 'run-server', 'Run the server', ->
coffee = spawn 'coffee', ['index.coffee']
coffee.stderr.on 'data', (data) -> console.log data.toString()
coffee.stdout.on 'data', (data) -> console.log data.toString()
task 'watch-src', 'Watch jade and coffee files for changes', ->
watch.watchTree 'source/libraries', {interval: 3000}, () ->
invoke 'build-lib'
watch.watchTree 'source/templates', {interval: 3000}, () ->
invoke 'build-templates'
watch.watchTree 'source/styles', {interval: 3000}, () ->
invoke 'build-styles'
watch.watchTree 'source/views', {interval: 3000}, () ->
invoke 'build-app'
watch.watchTree 'source/routers', {interval: 3000}, () ->
invoke 'build-app'
watch.watchTree 'source/models', {interval: 3000}, () ->
invoke 'build-app'
watch.watchTree 'source/collections', {interval: 3000}, () ->
invoke 'build-app'
task 'build-app', 'Watch coffee files for changes to rebuild the app', ->
now = +new Date()
if now - lastBuildAppTime < 1000
return false
js = snockets.getConcatenation './source/app.coffee'
fs.writeFileSync 'public/app.js', js
# coffee = spawn 'coffee', ['-c', '-j', 'app.js', '-o', 'public/', 'source/']
# coffee.stderr.on 'data', (data) -> console.log data.toString()
# coffee.stdout.on 'data', (data) -> console.log data.toString()
lastBuildAppTime = now
console.log "App has been built - #{helpers.formatTime(new Date(now))}"
task 'build-templates', 'Rebuild templates', ->
templatesBuffer = ''
clientjade = spawn 'clientjade', ['source/templates']
clientjade.stderr.on 'data', (data) -> console.log data.toString()
clientjade.stdout.on 'data', (data) -> templatesBuffer += data.toString()
clientjade.on 'close', (code, signal) -> fs.writeFileSync 'public/templates.js', templatesBuffer
console.log "Templates have been built - #{helpers.formatTime(new Date())}"
task 'build-styles', 'Rebuild styles', ->
sass = spawn 'sass', ['source/styles/index.sass','public/style.css']
sass.stderr.on 'data', (data) -> console.log data.toString()
sass.stdout.on 'data', (data) -> console.log data.toString()
console.log "Styles have been built - #{helpers.formatTime(new Date())}"
task 'build-lib', 'Build libraries into a single file', ->
librariesBuffer = ''
for file in libraries
librariesBuffer += fs.readFileSync('source/libraries/'+file+'.js') + "\n\n"
fs.writeFileSync 'public/lib.js', librariesBuffer
console.log "Libraries have been built - #{helpers.formatTime(new Date())}"