-
Notifications
You must be signed in to change notification settings - Fork 6
/
watch.coffee
36 lines (29 loc) · 963 Bytes
/
watch.coffee
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
chalk = require 'chalk'
fs = require 'fs'
childprocess = require 'child_process'
spawn = childprocess.spawn
app = null
spawnApp = ->
console.log chalk.green 'spawning app'
app = spawn 'coffee', ['server.coffee']
app.on 'close', (code, signal) ->
console.log chalk.green 'server.coffee closed with signal ', signal if signal
app.stdout.on 'data', (data) ->
console.log '' + data
app.stderr.on 'data', (data) ->
console.log chalk.red 'server.coffee STDERR: ', '' + data
cycleApp = ->
console.log chalk.yellow 'killing app'
app.kill()
spawnApp()
handleFileChange = (filename) ->
return if /^\.\#/.test(filename) # Fuck a color emacs temp
if /coffee$/.test(filename) == true
console.log chalk.yellow 'file changed: ', filename
console.log chalk.yellow 'cycling app'
cycleApp()
fs.watch '.', (event, filename) ->
handleFileChange filename
fs.watch 'lib', (event, filename) ->
handleFileChange filename
spawnApp()