-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgrunt.coffee
More file actions
111 lines (90 loc) · 2.81 KB
/
grunt.coffee
File metadata and controls
111 lines (90 loc) · 2.81 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
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
106
107
108
109
110
111
child_process = require('child_process')
http = require('http')
compileServer = false
useCabalDev = false
serverPort = 8000
retryTimeout = 300
serverProc = null
module.exports = (grunt) ->
grunt.initConfig
coffee:
compile:
files:
"public/js/modules/*.js": "src/coffee/**/*.coffee"
options:
flatten: false
bare: false
jade:
compile:
files:
"public/index.html": "src/jade/index.jade"
stylus:
compile:
files:
"public/css/styles.css": "src/stylus/styles.styl"
options:
compress: true
watch:
coffee:
files: ["src/coffee/**/*.coffee"]
tasks: ["coffee", "reload"]
stylus:
files: ["src/stylus/*.styl"]
tasks: ["stylus", "reload"]
jade:
files: ["src/jade/*.jade"]
tasks: ["jade", "reload"]
server:
files: ["src/hs/**/*.hs", "lib/**/*.hs"]
tasks: ["server", "reload"]
reload:
port: 6001
proxy:
host: 'localhost'
port: serverPort
grunt.registerTask "server", () ->
done = @async()
waitForServer = (callback) ->
req = http.get "http://localhost:#{serverPort}/", callback
req.on 'error', () ->
setTimeout (-> waitForServer callback), retryTimeout
triggerReload = () ->
grunt.task.run "reload"
execServer = () ->
if compileServer
console.log "===== Compiling httpd"
child_process.exec 'cabal-dev build', (err, stdout, stderr) ->
console.log stdout if stdout?
console.log stderr if stderr?
console.log "===== Starting httpd"
serverProc = child_process.spawn 'dist/build/hackfest-httpd/hackfest-httpd'
done()
else
console.log "===== Starting httpd"
if useCabalDev
child_process.exec 'ls -d cabal-dev/packages-*.conf', (err, pkgdir) ->
serverProc = child_process.spawn 'runghc', ['-isrc/hs', "-package-conf=#{pkgdir}", 'Main'],
stdio: 'inherit'
stderr: 'inherit'
waitForServer triggerReload
else
serverProc = child_process.spawn 'runghc', ['-isrc/hs', '-ilib', 'Main'],
stdio: 'inherit'
stderr: 'inherit'
waitForServer triggerReload
done()
if serverProc?
console.log "trying to kill old server"
if compileServer
serverProc.on 'close', execServer
serverProc.kill()
else
child_process.exec 'killall ghc', execServer
else
execServer()
return
grunt.loadNpmTasks "grunt-reload"
grunt.loadNpmTasks "grunt-contrib-coffee"
grunt.loadNpmTasks "grunt-contrib-jade"
grunt.loadNpmTasks "grunt-contrib-stylus"
grunt.registerTask "default", "coffee jade stylus server reload watch"