-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGruntfile.coffee
112 lines (102 loc) · 4.12 KB
/
Gruntfile.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
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
112
module.exports = (grunt) ->
grunt.initConfig
pkg: grunt.file.readJSON 'package.json'
external_daemon:
mongodb:
options:
startCheck: (stdout, stderr) ->
/waiting for connections/i.test stdout
cmd: 'mongod'
args: ['--dbpath', 'db']
beanstalkd:
cmd: 'beanstalkd'
shell:
'dbdir':
command: 'mkdir -p db'
'drop-test-db':
command: 'mongo tapline_test --exec "db.dropDatabase()"'
coffeelint:
options:
indentation:
value: 4
max_line_length:
value: 120
level: 'warn'
tapline:
expand: true
src: ['src/**/*.coffee', 'test/**/*.coffee']
coffee:
tapline:
expand: true
cwd: 'src'
src: ['**/*.coffee']
dest: 'lib'
ext: '.js'
tests:
expand: true
cwd: 'test'
src: ['**/*.coffee']
dest: 'test-js'
ext: '.js'
watch:
tapline:
files: ['src/**.coffee']
tasks: ['compile', 'server', 'worker']
options:
nospawn: true
mochacov:
test:
options:
reporter: 'spec'
grep: grunt.option('grep')
src: 'test-js/**/*.js'
html:
options:
reporter: 'html-cov'
output: 'coverage.html'
src: 'test-js/**/*.js'
reportcoverage:
options:
coveralls:
serviceName: 'travis-ci'
src: 'test-js/**/*.js'
grunt.loadNpmTasks 'grunt-external-daemon'
grunt.loadNpmTasks 'grunt-shell'
grunt.loadNpmTasks 'grunt-coffeelint'
grunt.loadNpmTasks 'grunt-contrib-coffee'
grunt.loadNpmTasks 'grunt-contrib-watch'
grunt.loadNpmTasks 'grunt-mocha-cov'
# The following is to run services during development and restart
# them as needed. Normally you could use grunt-develop, but it is
# limited to a single process and I need at least two: the API server
# and a job queue worker.
processes = {}
rundev = (name, command) ->
return ->
# Kill the process if it is currently running
if processes[name]
processes[name].kill()
delete processes[name]
# Spawn the new process
processes[name] = grunt.util.spawn cmd: process.argv[0], args: [command], -> false
# Print info when exiting or writing output to stdout
processes[name].on 'exit', (code, signal) ->
grunt.log.warn "#{name} exiting"
processes[name].stdout.on 'data', (buffer) ->
grunt.log.write "[#{name}] > ".cyan + String(buffer)
processes[name].stderr.on 'data', (buffer) ->
grunt.log.write "[#{name}] > ".red + String(buffer)
grunt.log.write '>> '.green + "Started #{name}"
# Cleanup any spawned processes on Ctrl-C
process.on 'exit', ->
for name, child of processes
child.kill()
grunt.registerTask 'worker', 'Start a job queue worker', rundev('worker', 'bin/tapline-worker.js')
grunt.registerTask 'server', 'Start a server', rundev('tapline', 'bin/tapline.js')
grunt.registerTask 'compile', ['coffeelint', 'coffee']
grunt.registerTask 'db', ['shell:dbdir', 'external_daemon:mongodb']
grunt.registerTask 'queue', ['external_daemon:beanstalkd']
grunt.registerTask 'test', ['db', 'shell:drop-test-db', 'compile', 'mochacov:test']
grunt.registerTask 'coverage', ['db', 'shell:drop-test-db', 'compile', 'mochacov:html']
grunt.registerTask 'coveralls', ['db', 'shell:drop-test-db', 'compile', 'mochacov:reportcoverage']
grunt.registerTask 'default', ['db', 'queue', 'compile', 'server', 'worker', 'watch']