forked from goodeggs/teacup
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCakefile
More file actions
61 lines (51 loc) · 1.69 KB
/
Copy pathCakefile
File metadata and controls
61 lines (51 loc) · 1.69 KB
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
'use strict'
{ spawn, fork, exec } = require 'child_process'
path = require 'path'
fs = require 'fs'
gaze = require 'gaze'
# Helpers
run = (command, callback) ->
exec command, (error, stdout, stderr) ->
process.stdout.write(stdout) if stdout
process.stderr.write(stderr) if stderr
callback(error, stdout, stderr) if callback
# Watchers
class Watchers
constructor: ->
self = @
gaze 'package.json', ->
@on 'changed', -> spawn('npm', ['install'], stdio: 'inherit')
.on 'exit', -> console.log 'npm packages updated'
gaze 'src/**/*.coffee', ->
@on 'all', (event, filePath) ->
self.compile(filePath)
@compile = (filePath) ->
filePath = filePath.replace("#{__dirname}/", '')
destDirPath = path.dirname(filePath).replace /^src/, 'lib'
run "./node_modules/.bin/coffee -mco #{destDirPath} #{filePath}", (error) ->
console.log "#{filePath} -> #{destDirPath}" if not error
run "./node_modules/.bin/uglifyjs -m -c -o lib/teacup.min.js lib/teacup.js"
exit: ->
# Tasks
task 'dev', 'development', ->
if not process.send # parent
runningDev = null
runDev = ->
console.log 'Start a new dev'
dev = spawn 'cake', ['dev'], stdio: [0, 1, 2, 'ipc']
dev.on 'message', (msg) ->
if msg is 'ready'
if runningDev
console.log 'Kill the old dev'
runningDev.send 'die'
runningDev = dev
runDev()
gaze 'Cakefile', ->
@on 'added', -> runDev()
@on 'changed', -> runDev()
else # child
watchers = new Watchers
# IPC
process.on 'exit', -> watchers.exit()
process.on 'message', (msg) -> process.exit() if msg is 'die'
process.send 'ready'