-
Notifications
You must be signed in to change notification settings - Fork 2
/
Gruntfile.js
58 lines (55 loc) · 1.55 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
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
clean: [ 'build' ]
});
grunt.loadNpmTasks('grunt-release');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.registerTask('default', ['build', 'test', 'clean']);
grunt.registerTask('build', 'build', function() {
var done = this.async();
require('child_process').exec(
'npm install',
function(error, stdout, stderr) {
grunt.log.writeln(stdout);
grunt.log.verbose.writeln(stderr);
if (error) {
grunt.log.error(error);
done(false);
}
else {
done(true);
}
}
);
});
grunt.registerTask('test', 'run tests', function() {
var done = this.async();
require('child_process').exec(
'npm test',
function(error, stdout, stderr) {
grunt.log.verbose.writeln(stdout);
grunt.log.verbose.writeln(stderr);
if (error) {
grunt.log.error(error);
done(false);
}
else {
// detect "# tests 12"
// "# fail 1"
var testsLine = stdout.match(/# tests\s+([0-9]+)/),
failLine = stdout.match(/# fail\s+([0-9]+)/);
if (failLine) {
grunt.fail.warn( failLine[1] + " of " + testsLine[1] + " tests failed." );
done(false);
return;
}
if (testsLine) {
grunt.log.oklns( "All " + testsLine[1] + " tests successful." ).ok();
}
done(true);
}
}
);
});
};