forked from github-tools/github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
82 lines (69 loc) · 1.86 KB
/
gulpfile.js
File metadata and controls
82 lines (69 loc) · 1.86 KB
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
'use strict';
var gulp = require('gulp');
var jshint = require('gulp-jshint');
var jscs = require('gulp-jscs');
var rename = require('gulp-rename');
var uglify = require('gulp-uglify');
var stylish = require('gulp-jscs-stylish');
var path = require('path');
var karma = require('karma');
gulp.task('lint', function() {
return gulp.src([
path.join(__dirname, '/*.js'),
path.join(__dirname, '/test/*.js')
],
{
base: './'
})
.pipe(jshint())
.pipe(jscs({
fix: true
}))
.pipe(stylish.combineWithHintResults())
.pipe(jscs.reporter())
.pipe(jshint.reporter('jshint-stylish'))
.pipe(gulp.dest('.'));
});
gulp.task('test', function(done) {
runTests(true, done);
});
gulp.task('test:auto', function(done) {
runTests(false, done);
});
gulp.task('build', function() {
return gulp.src('github.js')
.pipe(uglify())
.pipe(rename('github.min.js'))
.pipe(gulp.dest('dist/'));
});
gulp.task('default', function() {
gulp.start('lint', 'test', 'build');
});
function runTests (singleRun, done) {
var reporters = ['mocha'];
var preprocessors = {};
var pathSrcJs = [
path.join(__dirname, 'github.js'),
path.join(__dirname, 'test/*.js'),
path.join(__dirname, 'test/user.json')
];
if (singleRun) {
pathSrcJs.forEach(function(path) {
preprocessors[path] = ['coverage'];
});
reporters.push('coverage');
preprocessors['test/user.json'] = ['json_fixtures'];
}
var localConfig = {
files: pathSrcJs,
configFile: path.join(__dirname, './karma.conf.js'),
singleRun: singleRun,
autoWatch: !singleRun,
reporters: reporters,
preprocessors: preprocessors
};
var server = new karma.Server(localConfig, function(failCount) {
done(failCount ? new Error('Failed ' + failCount + ' tests.') : null);
});
server.start();
}