forked from gratipay/gratipay.com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
122 lines (101 loc) · 3.56 KB
/
Gruntfile.js
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
113
114
115
116
117
118
119
120
121
122
var http = require('http');
var spawn = require('child_process').spawn;
var fs = require('fs');
var ini = require('ini');
var env = ini.parse(fs.readFileSync('local.env', 'utf8'));
module.exports = function(grunt) {
'use strict';
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
watch: {
gruntfile: {
files: '<%= jshint.gruntfile %>',
tasks: 'jshint:gruntfile'
},
js: {
files: '<%= jshint.js %>',
tasks: ['jshint:js', 'karma:tests:run']
},
tests: {
files: '<%= jshint.tests %>',
tasks: ['jshint:tests', 'karma:tests:run']
}
},
jshint: {
gruntfile: 'Gruntfile.js',
js: 'js/**/*.{js,json}',
tests: 'jstests/**/*.js',
options: {
jshintrc: '.jshintrc',
globals: {
Gittip: true,
_gttp: true,
gttpURI: true,
alert: true
}
}
},
karma: {
tests: {
hostname: '0.0.0.0'
},
singlerun: {
singleRun: true
},
options: {
browsers: ['PhantomJS'],
reporters: 'dots',
frameworks: ['mocha', 'browserify'],
urlRoot: '/karma/',
proxies: { '/': 'http://' + env.CANONICAL_HOST + '/' },
files: [
'www/assets/jquery-1.10.2.min.js',
'www/assets/%version/utils.js',
'jstests/**/*.js',
],
browserify: { watch: true },
preprocessors: {
'jstests/**/*.js': ['browserify']
}
}
}
});
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-karma');
grunt.registerTask('default', ['test']);
grunt.registerTask('test', ['jshint', 'gittip:start', 'karma:singlerun']);
grunt.registerTask('gittip:start', 'Start Gittip test server (if necessary)', function gittipStart() {
var done = this.async();
http.get('http://' + env.CANONICAL_HOST + '/', function(res) {
grunt.log.writeln('Gittip seems to be running already. Doing nothing.');
done();
})
.on('error', function(e) {
grunt.log.write('Starting Gittip server...');
var started = false,
stdout = [],
gittip = spawn('make', ['run']);
gittip.stdout.setEncoding('utf8');
gittip.stdout.on('data', function(data) {
if (!started && /Greetings, program! Welcome to port 8537\./.test(data)) {
started = true;
grunt.log.writeln('started.');
setTimeout(done, 1000);
} else if (started && /Is something already running on port 8537/.test(data)) {
started = false;
} else
stdout.push(data);
});
gittip.on('exit', function() {
if (!started) {
grunt.log.writeln(stdout);
grunt.fail.fatal('Something went wrong when starting the Gittip server :<');
}
});
process.on('exit', function() {
gittip.kill();
});
});
});
};