/
gulpfile.js
77 lines (64 loc) · 2.37 KB
/
gulpfile.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
var gulp = require('gulp');
var deploy = require('gulp-gh-pages');
var exec = require('child_process').exec;
var fs = require('fs');
var lcov2badge = require('lcov2badge');
gulp.task('mkdir-build', function(callback){
fs.exists('build', function(exists){
if (!exists) {
fs.mkdir('build', callback);
} else {
callback();
}
});
});
///////////////
//Test coverage
gulp.task('test-cover', ['mkdir-build'], function(callback) {
exec('./node_modules/.bin/istanbul cover --dir ./build/coverage ./node_modules/.bin/_mocha', callback);
});
gulp.task('cover-badge', ['test-cover'], function(callback) {
lcov2badge.badge('./build/coverage/lcov.info', function(err, svgBadge){
if (err) return callback(err);
fs.writeFile('./build/coverage/badge.svg', svgBadge, callback);
});
});
//////////////
//Test results
gulp.task('test-badge', ['mkdir-build'], function(callback) {
exec('./node_modules/mocha/bin/_mocha --reporter mocha-reporter-badge > build/mocha-badge.svg', callback);
});
////////
// Lint
gulp.task('jshint', function(callback) {
exec('jshint .', function(err, stdout, stderr){
if (err) return callback(err);
console.log(stdout);
console.log(stderr);
callback();
});
});
gulp.task('jshint-html', ['mkdir-build'], function(callback) {
exec('jshint . --reporter node_modules/jshint-html-reporter/reporter.js > build/jshint.html', callback);
});
gulp.task('jshint-badge', ['mkdir-build'], function(callback) {
exec('jshint . --reporter node_modules/jshint-reporter-badge/index.js > build/jshint-badge.svg', callback);
});
gulp.task('lint', ['jshint', 'jshint-html', 'jshint-badge']);
////////////////////////
//Deployment on gh-pages
gulp.task('git-config', function(callback){
exec('git config --global user.email "alban.mouton@gmail.com" && git config --global user.name "Alban Mouton through Travis-CI"', callback);
});
gulp.task('deploy-build', ['cover-badge', 'test-badge', 'lint', 'git-config'], function() {
var deployOptions = {
cacheDir: './build/repos/shields-lightweight'
};
if (process.env.githubToken) {
console.log('"githubToken" environment variable found, use it to authenticate to github');
deployOptions.remoteUrl = 'https://' + process.env.githubToken + '@github.com/albanm/shields-lightweight';
}
return gulp.src('./build/**/*')
.pipe(deploy(deployOptions));
});
gulp.task('default', ['cover-badge', 'test-badge', 'lint']);