forked from gratipay/gratipay.com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
117 lines (94 loc) · 3.45 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
var http = require('http');
var spawn = require('child_process').spawn;
var fs = require('fs');
var ini = require('ini');
var yaml = require('js-yaml');
module.exports = function(grunt) {
'use strict';
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
env: ini.parse(
fs.readFileSync('defaults.env', 'utf8') +
fs.readFileSync('tests/test.env', 'utf8') +
(fs.existsSync('tests/local.env') ?
fs.readFileSync('tests/local.env', 'utf8') : '')
),
watch: {
gruntfile: {
files: '<%= jshint.gruntfile %>',
tasks: 'jshint:gruntfile'
},
js: {
files: '<%= jshint.js %>',
tasks: ['jshint:js', 'dalek']
},
tests: {
files: '<%= jshint.tests %>',
tasks: ['jshint:tests', 'dalek']
}
},
jshint: {
gruntfile: 'Gruntfile.js',
js: 'js/**/*.{js,json}',
tests: 'tests/js/**/*.js',
options: {
jshintrc: '.jshintrc',
globals: {
Gratipay: true,
_gttp: true,
gttpURI: true,
alert: true
}
}
},
dalek: {
tests: 'tests/js/**/test_*.js'
}
});
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-dalek');
grunt.registerTask('default', ['test']);
grunt.registerTask('test', ['jshint', 'aspen:start', 'dalek']);
grunt.registerTask('aspen:start', 'Start Aspen (if necessary)', function() {
var done = this.async();
grunt.config.requires('env.CANONICAL_HOST');
var canonicalHost = grunt.config.get('env.CANONICAL_HOST') || 'localhost:8537';
http.get('http://' + canonicalHost + '/', function(res) {
grunt.log.writeln('Aspen seems to be running already. Doing nothing.');
done();
})
.on('error', function(e) {
grunt.log.write('Starting Aspen...');
var started = false;
var aspen_out = [];
var bin = 'env/' + (process.platform == 'win32' ? 'Scripts' : 'bin');
var child = spawn(bin+'/gunicorn',
['--bind', ':8537', '--workers', '1', 'aspen.wsgi:website'],
{env: grunt.config.get('env')});
child.stdout.setEncoding('utf8');
child.stderr.setEncoding('utf8');
child.stdout.on('data', function(data) { aspen_out.push(data); });
child.stderr.on('data', function(data) {
aspen_out.push(data);
if (!started && /Starting gunicorn /.test(data)) {
grunt.log.writeln(' started.');
setTimeout(function() {
started = true;
done();
}, 1000);
}
});
child.on('exit', function() {
if (!started) {
grunt.log.writeln(' failed!');
grunt.log.write(aspen_out);
grunt.fail.fatal('Something went wrong when starting Aspen :<');
}
});
process.on('exit', function() {
child.kill();
});
});
});
};